mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-27 12:37:39 +00:00
Sleep when there is nothing to wait
This commit is contained in:
parent
21984fac8b
commit
bb15671046
@ -70,19 +70,15 @@ static int parse_ppid(int pid) {
|
|||||||
return ppid;
|
return ppid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long xptrace(bool log, int request, pid_t pid, void *addr, void *data) {
|
static inline long xptrace(int request, pid_t pid, void *addr, void *data) {
|
||||||
long ret = ptrace(request, pid, addr, data);
|
long ret = ptrace(request, pid, addr, data);
|
||||||
if (log && ret == -1)
|
if (ret < 0)
|
||||||
PLOGE("ptrace %d", pid);
|
PLOGE("ptrace %d", pid);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long xptrace(int request, pid_t pid, void *addr, void *data) {
|
static inline long xptrace(int request, pid_t pid, void *addr = nullptr, intptr_t data = 0) {
|
||||||
return xptrace(true, request, pid, addr, data);
|
return xptrace(request, pid, addr, reinterpret_cast<void *>(data));
|
||||||
}
|
|
||||||
|
|
||||||
static long xptrace(int request, pid_t pid, void *addr = nullptr, intptr_t data = 0) {
|
|
||||||
return xptrace(true, request, pid, addr, reinterpret_cast<void *>(data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_packages_xml(string_view s) {
|
static bool parse_packages_xml(string_view s) {
|
||||||
@ -254,6 +250,7 @@ static void inotify_event(int) {
|
|||||||
uid_proc_map.clear();
|
uid_proc_map.clear();
|
||||||
file_readline("/data/system/packages.xml", parse_packages_xml, true);
|
file_readline("/data/system/packages.xml", parse_packages_xml, true);
|
||||||
} else if (event->mask & IN_ACCESS) {
|
} else if (event->mask & IN_ACCESS) {
|
||||||
|
LOGD("proc_monitor: app_process access\n");
|
||||||
check_zygote();
|
check_zygote();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -409,8 +406,19 @@ void proc_monitor() {
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const int pid = waitpid(-1, &status, __WALL | __WNOTHREAD);
|
const int pid = waitpid(-1, &status, __WALL | __WNOTHREAD);
|
||||||
if (pid < 0)
|
if (pid < 0) {
|
||||||
|
if (errno == ECHILD) {
|
||||||
|
/* This mean we have nothing to wait, sleep
|
||||||
|
* and wait till signal interruption */
|
||||||
|
LOGD("proc_monitor: nothing to monitor, wait for signal\n");
|
||||||
|
struct timespec timespec = {
|
||||||
|
.tv_sec = INT_MAX,
|
||||||
|
.tv_nsec = 0
|
||||||
|
};
|
||||||
|
nanosleep(×pec, nullptr);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
bool detach = false;
|
bool detach = false;
|
||||||
RunFinally detach_task([&]() -> void {
|
RunFinally detach_task([&]() -> void {
|
||||||
if (detach) {
|
if (detach) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user