Fix a bug causing magiskhide CLI freezing

This commit is contained in:
topjohnwu 2018-11-13 02:22:55 -05:00
parent ef40c1212e
commit 89e0be0099
4 changed files with 9 additions and 5 deletions

View File

@ -576,7 +576,7 @@ static bool check_data() {
return data; return data;
} }
extern int launch_magiskhide(); extern int launch_magiskhide(int client = -1);
static void *start_magisk_hide(void *) { static void *start_magisk_hide(void *) {
launch_magiskhide(); launch_magiskhide();

View File

@ -32,7 +32,7 @@ pthread_mutex_t list_lock;
exit(1); exit(1);
} }
int launch_magiskhide() { int launch_magiskhide(int client) {
if (hide_enabled) if (hide_enabled)
return HIDE_IS_ENABLED; return HIDE_IS_ENABLED;
@ -62,9 +62,12 @@ int launch_magiskhide() {
// Get thread reference // Get thread reference
proc_monitor_thread = pthread_self(); proc_monitor_thread = pthread_self();
if (client >= 0) {
write_int(client, DAEMON_SUCCESS);
close(client);
}
// Start monitoring // Start monitoring
proc_monitor(); proc_monitor();
return DAEMON_SUCCESS;
error: error:
hide_enabled = 0; hide_enabled = 0;
@ -101,7 +104,7 @@ void magiskhide_handler(int client) {
switch (req) { switch (req) {
case LAUNCH_MAGISKHIDE: case LAUNCH_MAGISKHIDE:
res = launch_magiskhide(); res = launch_magiskhide(client);
break; break;
case STOP_MAGISKHIDE: case STOP_MAGISKHIDE:
res = stop_magiskhide(); res = stop_magiskhide();

View File

@ -10,7 +10,7 @@
#define TERM_THREAD SIGUSR1 #define TERM_THREAD SIGUSR1
// Daemon entries // Daemon entries
int launch_magiskhide(); int launch_magiskhide(int client);
int stop_magiskhide(); int stop_magiskhide();
int add_list(int client); int add_list(int client);
int rm_list(int client); int rm_list(int client);

View File

@ -200,4 +200,5 @@ void proc_monitor() {
if (fork_dont_care() == 0) if (fork_dont_care() == 0)
hide_daemon(pid); hide_daemon(pid);
} }
pthread_exit(nullptr);
} }