Don't check zygote in busy loop

This commit is contained in:
topjohnwu 2019-05-27 16:27:19 -07:00
parent 81aa56f60f
commit a3a1aed723

View File

@ -123,25 +123,17 @@ void update_uid_map() {
} }
static void check_zygote() { static void check_zygote() {
int min_zyg = 1; crawl_procfs([](int pid) -> bool {
if (access("/system/bin/app_process64", R_OK) == 0) char buf[512];
min_zyg = 2; snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
for (;;) { if (FILE *f = fopen(buf, "re"); f) {
crawl_procfs([](int pid) -> bool { fgets(buf, sizeof(buf), f);
char buf[512]; if (strncmp(buf, "zygote", 6) == 0 && parse_ppid(pid) == 1)
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); new_zygote(pid);
if (FILE *f = fopen(buf, "re"); f) { fclose(f);
fgets(buf, sizeof(buf), f); }
if (strncmp(buf, "zygote", 6) == 0 && parse_ppid(pid) == 1) return true;
new_zygote(pid); });
fclose(f);
}
return true;
});
if (zygote_map.size() >= min_zyg)
break;
usleep(10000);
}
} }
#define APP_PROC "/system/bin/app_process" #define APP_PROC "/system/bin/app_process"
@ -189,14 +181,9 @@ static void inotify_event(int) {
char buf[512]; char buf[512];
auto event = reinterpret_cast<struct inotify_event *>(buf); auto event = reinterpret_cast<struct inotify_event *>(buf);
read(inotify_fd, buf, sizeof(buf)); read(inotify_fd, buf, sizeof(buf));
if ((event->mask & IN_CLOSE_WRITE) && strcmp(event->name, "packages.xml") == 0) { if ((event->mask & IN_CLOSE_WRITE) && event->name == "packages.xml"sv)
LOGD("proc_monitor: /data/system/packages.xml updated\n"); update_uid_map();
uid_proc_map.clear(); check_zygote();
file_readline("/data/system/packages.xml", parse_packages_xml, true);
} else if (event->mask & IN_ACCESS) {
LOGD("proc_monitor: app_process access\n");
check_zygote();
}
} }
// Workaround for the lack of pthread_cancel // Workaround for the lack of pthread_cancel