diff --git a/jni/daemon/bootstages.c b/jni/daemon/bootstages.c index 585e33779..d9b2714ef 100644 --- a/jni/daemon/bootstages.c +++ b/jni/daemon/bootstages.c @@ -551,11 +551,6 @@ static int prepare_img() { * Entry points * ****************/ -static void *start_magisk_hide(void *args) { - launch_magiskhide(-1); - return NULL; -} - static void unblock_boot_process() { close(open(UNBLOCKFILE, O_RDONLY | O_CREAT)); pthread_exit(NULL); @@ -728,14 +723,8 @@ core_only: bind_mount(HOSTSFILE, "/system/etc/hosts"); } - // Enable magiskhide by default, only disable when set explicitly - char *hide_prop = getprop(MAGISKHIDE_PROP); - if (hide_prop == NULL || strcmp(hide_prop, "0") != 0) { - pthread_t thread; - xpthread_create(&thread, NULL, start_magisk_hide, NULL); - pthread_detach(thread); - } - free(hide_prop); + auto_start_magiskhide(); + unblock: unblock_boot_process(); diff --git a/jni/daemon/daemon.c b/jni/daemon/daemon.c index b05d92df8..f78481b83 100644 --- a/jni/daemon/daemon.c +++ b/jni/daemon/daemon.c @@ -21,8 +21,10 @@ #include "utils.h" #include "daemon.h" #include "magiskpolicy.h" +#include "resetprop.h" pthread_t sepol_patch; +int is_restart = 0; static void *request_handler(void *args) { // Setup the default error handler for threads @@ -114,6 +116,21 @@ static void *large_sepol_patch(void *args) { return NULL; } +static void *start_magisk_hide(void *args) { + launch_magiskhide(-1); + return NULL; +} + +void auto_start_magiskhide() { + char *hide_prop = getprop2(MAGISKHIDE_PROP, 1); + if (hide_prop == NULL || strcmp(hide_prop, "0") != 0) { + pthread_t thread; + xpthread_create(&thread, NULL, start_magisk_hide, NULL); + pthread_detach(thread); + } + free(hide_prop); +} + void start_daemon() { setcon("u:r:su:s0"); umask(0); @@ -123,9 +140,17 @@ void start_daemon() { xdup2(fd, STDERR_FILENO); close(fd); + if ((is_restart = check_data())) { + // Restart many stuffs + auto_start_magiskhide(); + start_debug_log(); + } + // Start the log monitor monitor_logs(); + LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n"); + // Patch selinux with medium patch before we do anything load_policydb(SELINUX_POLICY); sepol_med_rules(); @@ -146,8 +171,6 @@ void start_daemon() { // It should stay intact under any circumstances err_handler = do_nothing; - LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n"); - // Unlock all blocks for rw unlock_blocks(); diff --git a/jni/daemon/log_monitor.c b/jni/daemon/log_monitor.c index f496ee4b1..7aff8f062 100644 --- a/jni/daemon/log_monitor.c +++ b/jni/daemon/log_monitor.c @@ -15,8 +15,7 @@ #include "utils.h" int logcat_events[] = { -1, -1, -1 }; - -static int is_restart = 0; +extern int is_restart; #ifdef MAGISK_DEBUG static int debug_log_pid, debug_log_fd; @@ -120,20 +119,10 @@ static void *debug_magisk_log_thread(void *args) { void monitor_logs() { pthread_t thread; - is_restart = check_data(); - // Start log file dumper before monitor xpthread_create(&thread, NULL, magisk_log_thread, NULL); pthread_detach(thread); -#ifdef MAGISK_DEBUG - if (is_restart) { - // Restart debug logs - xpthread_create(&thread, NULL, debug_magisk_log_thread, NULL); - pthread_detach(thread); - } -#endif - // Start logcat monitor xpthread_create(&thread, NULL, logger_thread, NULL); pthread_detach(thread); @@ -158,5 +147,15 @@ void stop_debug_full_log() { // Start debug thread xpthread_create(&thread, NULL, debug_magisk_log_thread, NULL); pthread_detach(thread); + start_debug_log(); +#endif +} + +void start_debug_log() { +#ifdef MAGISK_DEBUG + pthread_t thread; + // Start debug thread + xpthread_create(&thread, NULL, debug_magisk_log_thread, NULL); + pthread_detach(thread); #endif } diff --git a/jni/include/daemon.h b/jni/include/daemon.h index abe994e4b..74a21b8de 100644 --- a/jni/include/daemon.h +++ b/jni/include/daemon.h @@ -7,6 +7,7 @@ #include extern pthread_t sepol_patch; +extern int is_restart; // Commands require connecting to daemon typedef enum { @@ -40,6 +41,7 @@ typedef enum { void start_daemon(); int connect_daemon(); +void auto_start_magiskhide(); // socket_trans.c diff --git a/jni/include/logging.h b/jni/include/logging.h index 11673ebd5..2738e7301 100644 --- a/jni/include/logging.h +++ b/jni/include/logging.h @@ -44,6 +44,7 @@ extern int logcat_events[]; void monitor_logs(); void start_debug_full_log(); void stop_debug_full_log(); +void start_debug_log(); #else // IS_DAEMON diff --git a/jni/magiskhide/magiskhide.c b/jni/magiskhide/magiskhide.c index d899465b6..7b45e7aa7 100644 --- a/jni/magiskhide/magiskhide.c +++ b/jni/magiskhide/magiskhide.c @@ -124,6 +124,8 @@ int magiskhide_main(int argc, char *argv[]) { req = RM_HIDELIST; } else if (strcmp(argv[1], "--ls") == 0) { req = LS_HIDELIST; + } else { + usage(argv[0]); } int fd = connect_daemon(); write_int(fd, req);