From 8a2f0063d424cdcee0a429d6553d76f1b03f678b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 16 Apr 2017 02:43:19 +0800 Subject: [PATCH] Improve magiskhide process/thread management --- jni/magiskhide/magiskhide.c | 9 ++++++++- jni/magiskhide/proc_monitor.c | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/jni/magiskhide/magiskhide.c b/jni/magiskhide/magiskhide.c index f3429e839..d533c30c3 100644 --- a/jni/magiskhide/magiskhide.c +++ b/jni/magiskhide/magiskhide.c @@ -17,7 +17,7 @@ #include "magiskhide.h" #include "daemon.h" -int sv[2], hide_pid; +int sv[2], hide_pid = -1; struct vector *hide_list, *new_list; int isEnabled = 0; @@ -88,6 +88,13 @@ void launch_magiskhide(int client) { error: write_int(client, 1); close(client); + if (hide_pid != -1) { + int kill = -1; + // Kill hide daemon + write(sv[0], &kill, sizeof(kill)); + close(sv[0]); + waitpid(hide_pid, NULL, 0); + } return; } diff --git a/jni/magiskhide/proc_monitor.c b/jni/magiskhide/proc_monitor.c index 5d65095e6..b0442beed 100644 --- a/jni/magiskhide/proc_monitor.c +++ b/jni/magiskhide/proc_monitor.c @@ -19,6 +19,7 @@ static int zygote_num = 0; static char init_ns[32], zygote_ns[2][32]; +static FILE *p; static void read_namespace(const int pid, char* target, const size_t size) { char path[32]; @@ -43,6 +44,7 @@ static void quit_pthread(int sig) { hide_list = new_list = NULL; isEnabled = 0; LOGD("proc_monitor: terminating...\n"); + pclose(p); pthread_exit(NULL); } @@ -72,7 +74,6 @@ void *proc_monitor(void *args) { int pid; char buffer[512]; - FILE *p; // Get the mount namespace of init read_namespace(1, init_ns, 32);