mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-02 21:01:50 +00:00
Make sure logcat process does not become a zombie
This commit is contained in:
@@ -645,11 +645,23 @@ static void dump_logs() {
|
||||
if (test != 0)
|
||||
return;
|
||||
rename(LOGFILE, LOGFILE ".bak");
|
||||
int fd = xopen(LOGFILE, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0644);
|
||||
exec_t exec { .fd = fd };
|
||||
exec_command(exec, "/system/bin/logcat", "-s", "Magisk");
|
||||
log_dump = true;
|
||||
close(fd);
|
||||
// Start a daemon thread and wait indefinitely
|
||||
new_daemon_thread([](auto) -> void* {
|
||||
int fd = xopen(LOGFILE, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0644);
|
||||
exec_t exec {
|
||||
.fd = fd,
|
||||
.fork = fork_no_zombie
|
||||
};
|
||||
int pid = exec_command(exec, "/system/bin/logcat", "-s", "Magisk");
|
||||
close(fd);
|
||||
if (pid < 0) {
|
||||
log_dump = false;
|
||||
return nullptr;
|
||||
}
|
||||
waitpid(pid, nullptr, 0);
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
/****************
|
||||
|
||||
@@ -140,20 +140,17 @@ static void main_daemon() {
|
||||
pthread_sigmask(SIG_SETMASK, &block_set, nullptr);
|
||||
|
||||
// Loop forever to listen for requests
|
||||
while(true) {
|
||||
for (;;) {
|
||||
int *client = new int;
|
||||
*client = xaccept4(fd, nullptr, nullptr, SOCK_CLOEXEC);
|
||||
pthread_t thread;
|
||||
xpthread_create(&thread, nullptr, request_handler, client);
|
||||
// Detach the thread, we will never join it
|
||||
pthread_detach(thread);
|
||||
new_daemon_thread(request_handler, client);
|
||||
}
|
||||
}
|
||||
|
||||
int switch_mnt_ns(int pid) {
|
||||
char mnt[32];
|
||||
snprintf(mnt, sizeof(mnt), "/proc/%d/ns/mnt", pid);
|
||||
if(access(mnt, R_OK) == -1) return 1; // Maybe process died..
|
||||
if (access(mnt, R_OK) == -1) return 1; // Maybe process died..
|
||||
|
||||
int fd, ret;
|
||||
fd = xopen(mnt, O_RDONLY);
|
||||
|
||||
Reference in New Issue
Block a user