Only care about the first event

This commit is contained in:
topjohnwu 2019-02-16 02:49:36 -05:00
parent 3c56f38229
commit 6412bfc7b5

View File

@ -310,26 +310,21 @@ void proc_monitor() {
sigaction(TERM_THREAD, &act, nullptr); sigaction(TERM_THREAD, &act, nullptr);
// Read inotify events // Read inotify events
struct inotify_event *event;
ssize_t len; ssize_t len;
char *p;
char buf[4096]; char buf[4096];
auto event = reinterpret_cast<inotify_event *>(buf);
while ((len = read(inotify_fd, buf, sizeof(buf))) >= 0) { while ((len = read(inotify_fd, buf, sizeof(buf))) >= 0) {
for (p = buf; p < buf + len; ) { if (len < sizeof(*event))
event = (struct inotify_event *)p; continue;
if (event->mask & IN_OPEN) { if (event->mask & IN_OPEN) {
// Since we're just watching files, // Since we're just watching files,
// extracting file name is not possible from querying event // extracting file name is not possible from querying event
MutexGuard lock(list_lock); MutexGuard lock(list_lock);
crawl_procfs(process_pid); crawl_procfs(process_pid);
} else if (!(event->mask & IN_IGNORED)) { } else if (!(event->mask & IN_IGNORED)) {
LOGD("proc_monitor: inotify: /data/app change detected\n"); LOGD("proc_monitor: inotify: /data/app change detected\n");
update_inotify_mask(true); update_inotify_mask(true);
break;
}
p += sizeof(*event) + event->len;
} }
} }
PLOGE("proc_monitor: read inotify"); PLOGE("proc_monitor: read inotify");