Ignore outdated inotify events

This commit is contained in:
Bert Münnich 2018-02-18 13:13:11 +01:00
parent 6d1e00627b
commit 48e0b70ad3

View File

@ -85,7 +85,7 @@ bool arl_handle(arl_t *arl)
{ {
bool reload = false; bool reload = false;
char *ptr; char *ptr;
const struct inotify_event *event; const struct inotify_event *e;
for (;;) { for (;;) {
ssize_t len = read(arl->fd, buf.d, sizeof(buf.d)); ssize_t len = read(arl->fd, buf.d, sizeof(buf.d));
@ -95,14 +95,14 @@ bool arl_handle(arl_t *arl)
continue; continue;
break; break;
} }
for (ptr = buf.d; ptr < buf.d + len; ptr += sizeof(*event) + event->len) { for (ptr = buf.d; ptr < buf.d + len; ptr += sizeof(*e) + e->len) {
event = (const struct inotify_event*) ptr; e = (const struct inotify_event*) ptr;
if (event->mask & IN_CLOSE_WRITE) { if (e->wd == arl->wd_file && (e->mask & IN_CLOSE_WRITE)) {
reload = true; reload = true;
} else if (event->mask & IN_DELETE_SELF) { } else if (e->wd == arl->wd_file && (e->mask & IN_DELETE_SELF)) {
rm_watch(arl->fd, &arl->wd_file); rm_watch(arl->fd, &arl->wd_file);
} else if (event->mask & (IN_CREATE | IN_MOVED_TO)) { } else if (e->wd == arl->wd_dir && (e->mask & (IN_CREATE | IN_MOVED_TO))) {
if (STREQ(event->name, arl->filename)) if (STREQ(e->name, arl->filename))
reload = true; reload = true;
} }
} }