Page MenuHomeFreeBSD

D58050.diff
No OneTemporary

D58050.diff

diff --git a/sys/kern/vfs_inotify.c b/sys/kern/vfs_inotify.c
--- a/sys/kern/vfs_inotify.c
+++ b/sys/kern/vfs_inotify.c
@@ -614,25 +614,37 @@
struct inotify_watch key;
struct inotify_softc *sc;
struct inotify_record *rec;
- bool allocfail;
+ bool allocfail, delete, notify, oneshot, unmount;
mtx_assert(&watch->vp->v_pollinfo->vpi_lock, MA_OWNED);
sc = watch->sc;
- rec = inotify_alloc_record(watch->wd, name, namelen, event, cookie,
- M_NOWAIT);
- if (rec == NULL) {
- rec = &sc->overflow;
- allocfail = true;
+
+ delete = (event & IN_DELETE_SELF) != 0;
+ notify = (watch->mask & event) != 0;
+ oneshot = (watch->mask & IN_ONESHOT) != 0;
+ unmount = (event & IN_UNMOUNT) != 0;
+ if (!notify && !delete && !unmount)
+ return;
+
+ if (notify || unmount) {
+ rec = inotify_alloc_record(watch->wd, name, namelen, event,
+ cookie, M_NOWAIT);
+ if (rec == NULL) {
+ rec = &sc->overflow;
+ allocfail = true;
+ } else {
+ allocfail = false;
+ }
} else {
- allocfail = false;
+ rec = NULL;
}
mtx_lock(&sc->lock);
- if (!inotify_queue_record(sc, rec) && rec != &sc->overflow)
+ if (rec != NULL && !inotify_queue_record(sc, rec) &&
+ rec != &sc->overflow)
free(rec, M_INOTIFY);
- if ((watch->mask & IN_ONESHOT) != 0 ||
- (event & (IN_DELETE_SELF | IN_UNMOUNT)) != 0) {
+ if (oneshot || delete || unmount) {
if (!allocfail) {
rec = inotify_alloc_record(watch->wd, NULL, 0,
IN_IGNORED, 0, M_NOWAIT);
@@ -676,8 +688,7 @@
TAILQ_FOREACH_SAFE(watch, &vp->v_pollinfo->vpi_inotify, vlink, tmp) {
KASSERT(watch->vp == vp,
("inotify_log: watch %p vp != vp", watch));
- if ((watch->mask & event) != 0 || event == IN_UNMOUNT)
- inotify_log_one(watch, name, namelen, event, cookie);
+ inotify_log_one(watch, name, namelen, event, cookie);
}
mtx_unlock(&vp->v_pollinfo->vpi_lock);
}
diff --git a/tests/sys/kern/inotify_test.c b/tests/sys/kern/inotify_test.c
--- a/tests/sys/kern/inotify_test.c
+++ b/tests/sys/kern/inotify_test.c
@@ -54,6 +54,8 @@
return ("IN_MOVED_TO");
case IN_OPEN:
return ("IN_OPEN");
+ case IN_IGNORED:
+ return ("IN_IGNORED");
default:
return (NULL);
}
@@ -832,6 +834,27 @@
close_inotify(ifd);
}
+ATF_TC_WITHOUT_HEAD(inotify_event_delete_ignored);
+ATF_TC_BODY(inotify_event_delete_ignored, tc)
+{
+ char path[PATH_MAX];
+ int error, ifd, wd;
+
+ ifd = inotify(IN_NONBLOCK);
+
+ wd = watch_dir(ifd, IN_DELETE, path);
+
+ /*
+ * IN_IGNORED should be generated when a watched directory is removed,
+ * even if the watch was not configured to raise IN_DELETE_SELF.
+ */
+ error = rmdir(path);
+ ATF_REQUIRE(error == 0);
+ consume_event(ifd, wd, 0, IN_IGNORED, NULL);
+
+ close_inotify(ifd);
+}
+
ATF_TC_WITHOUT_HEAD(inotify_event_move);
ATF_TC_BODY(inotify_event_move, tc)
{
@@ -999,6 +1022,7 @@
ATF_TP_ADD_TC(tp, inotify_event_close_write);
ATF_TP_ADD_TC(tp, inotify_event_create);
ATF_TP_ADD_TC(tp, inotify_event_delete);
+ ATF_TP_ADD_TC(tp, inotify_event_delete_ignored);
ATF_TP_ADD_TC(tp, inotify_event_move);
ATF_TP_ADD_TC(tp, inotify_event_move_dir);
ATF_TP_ADD_TC(tp, inotify_event_open);

File Metadata

Mime Type
text/plain
Expires
Wed, Jul 8, 4:30 PM (7 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34851671
Default Alt Text
D58050.diff (3 KB)

Event Timeline