nsxiv48e0b70
Ignore outdated inotify events
+7 −7
1 file changed
- M autoreload_inotify.c +7 −7
| @@ -85,7 +85,7 @@ bool arl_handle(arl_t *arl) | |||
| 85 | 85 | { | |
| 86 | 86 | bool reload = false; | |
| 87 | 87 | char *ptr; | |
| 88 | − | const struct inotify_event *event; | |
| 88 | + | const struct inotify_event *e; | |
| 89 | 89 | ||
| 90 | 90 | for (;;) { | |
| 91 | 91 | ssize_t len = read(arl->fd, buf.d, sizeof(buf.d)); | |
| @@ -95,14 +95,14 @@ bool arl_handle(arl_t *arl) | |||
| 95 | 95 | continue; | |
| 96 | 96 | break; | |
| 97 | 97 | } | |
| 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)) { | |
| 101 | 101 | reload = true; | |
| 102 | − | } else if (event->mask & IN_DELETE_SELF) { | |
| 102 | + | } else if (e->wd == arl->wd_file && (e->mask & IN_DELETE_SELF)) { | |
| 103 | 103 | 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)) | |
| 106 | 106 | reload = true; | |
| 107 | 107 | } | |
| 108 | 108 | } | |