Krolyxon
Commit 48e0b70

Branches

Refs →

nsxiv48e0b70

Ignore outdated inotify events

Author
Bert Münnich
Date
2018-02-18 13:13 +0100
Committer
Bert Münnich · 2018-02-18 14:12 +0100
Parent
6d1e006
Commit
48e0b70ad3dd550bf29810ec9b4f6ebdab3d7605

+7 −7

1 file changed

  1. M autoreload_inotify.c +7 −7
M autoreload_inotify.c View
@@ -85,7 +85,7 @@ bool arl_handle(arl_t *arl)
8585 {
8686 bool reload = false;
8787 char *ptr;
88− const struct inotify_event *event;
88+ const struct inotify_event *e;
8989
9090 for (;;) {
9191 ssize_t len = read(arl->fd, buf.d, sizeof(buf.d));
@@ -95,14 +95,14 @@ bool arl_handle(arl_t *arl)
9595 continue;
9696 break;
9797 }
98− for (ptr = buf.d; ptr < buf.d + len; ptr += sizeof(*event) + event->len) {
99− event = (const struct inotify_event*) ptr;
100− if (event->mask & IN_CLOSE_WRITE) {
98+ for (ptr = buf.d; ptr < buf.d + len; ptr += sizeof(*e) + e->len) {
99+ e = (const struct inotify_event*) ptr;
100+ if (e->wd == arl->wd_file && (e->mask & IN_CLOSE_WRITE)) {
101101 reload = true;
102− } else if (event->mask & IN_DELETE_SELF) {
102+ } else if (e->wd == arl->wd_file && (e->mask & IN_DELETE_SELF)) {
103103 rm_watch(arl->fd, &arl->wd_file);
104− } else if (event->mask & (IN_CREATE | IN_MOVED_TO)) {
105− if (STREQ(event->name, arl->filename))
104+ } else if (e->wd == arl->wd_dir && (e->mask & (IN_CREATE | IN_MOVED_TO))) {
105+ if (STREQ(e->name, arl->filename))
106106 reload = true;
107107 }
108108 }