From 6412bfc7b5cbf42e23e6aff9d9cf718061008803 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 16 Feb 2019 02:49:36 -0500 Subject: [PATCH] Only care about the first event --- native/jni/magiskhide/proc_monitor.cpp | 27 +++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/native/jni/magiskhide/proc_monitor.cpp b/native/jni/magiskhide/proc_monitor.cpp index b94830ee9..7c85c20ce 100644 --- a/native/jni/magiskhide/proc_monitor.cpp +++ b/native/jni/magiskhide/proc_monitor.cpp @@ -310,26 +310,21 @@ void proc_monitor() { sigaction(TERM_THREAD, &act, nullptr); // Read inotify events - struct inotify_event *event; ssize_t len; - char *p; char buf[4096]; + auto event = reinterpret_cast(buf); while ((len = read(inotify_fd, buf, sizeof(buf))) >= 0) { - for (p = buf; p < buf + len; ) { - event = (struct inotify_event *)p; + if (len < sizeof(*event)) + continue; - if (event->mask & IN_OPEN) { - // Since we're just watching files, - // extracting file name is not possible from querying event - MutexGuard lock(list_lock); - crawl_procfs(process_pid); - } else if (!(event->mask & IN_IGNORED)) { - LOGD("proc_monitor: inotify: /data/app change detected\n"); - update_inotify_mask(true); - break; - } - - p += sizeof(*event) + event->len; + if (event->mask & IN_OPEN) { + // Since we're just watching files, + // extracting file name is not possible from querying event + MutexGuard lock(list_lock); + crawl_procfs(process_pid); + } else if (!(event->mask & IN_IGNORED)) { + LOGD("proc_monitor: inotify: /data/app change detected\n"); + update_inotify_mask(true); } } PLOGE("proc_monitor: read inotify");