From cddeaffada150a6f10de5329067f6a3352af5368 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 13 Oct 2017 22:25:16 +0800 Subject: [PATCH] Remove err_handler --- jni/daemon/bootstages.c | 6 ------ jni/daemon/daemon.c | 6 ------ jni/daemon/log_monitor.c | 9 --------- jni/daemon/magisk.c | 6 ------ jni/include/logging.h | 10 +--------- jni/magiskhide/hide_utils.c | 3 --- jni/magiskhide/magiskhide.c | 3 --- jni/magiskhide/proc_monitor.c | 17 +---------------- jni/su | 2 +- jni/utils/misc.c | 3 --- 10 files changed, 3 insertions(+), 62 deletions(-) diff --git a/jni/daemon/bootstages.c b/jni/daemon/bootstages.c index dcb3c748d..3755ccad2 100644 --- a/jni/daemon/bootstages.c +++ b/jni/daemon/bootstages.c @@ -574,9 +574,6 @@ static void unblock_boot_process() { } void post_fs(int client) { - // Error handler - err_handler = unblock_boot_process; - LOGI("** post-fs mode running\n"); // ack write_int(client, 0); @@ -598,9 +595,6 @@ unblock: } void post_fs_data(int client) { - // Error handler - err_handler = unblock_boot_process; - // ack write_int(client, 0); close(client); diff --git a/jni/daemon/daemon.c b/jni/daemon/daemon.c index c324a7cb2..d73fffb69 100644 --- a/jni/daemon/daemon.c +++ b/jni/daemon/daemon.c @@ -27,9 +27,6 @@ pthread_t sepol_patch; int is_restart = 0; static void *request_handler(void *args) { - // Setup the default error handler for threads - err_handler = exit_thread; - int client = *((int *) args); free(args); client_request req = read_int(client); @@ -168,9 +165,6 @@ void start_daemon() { // Change process name strcpy(argv0, "magisk_daemon"); - // The root daemon should not do anything if an error occurs - // It should stay intact under any circumstances - err_handler = do_nothing; // Unlock all blocks for rw unlock_blocks(); diff --git a/jni/daemon/log_monitor.c b/jni/daemon/log_monitor.c index 88f28152e..2bf515cae 100644 --- a/jni/daemon/log_monitor.c +++ b/jni/daemon/log_monitor.c @@ -22,9 +22,6 @@ static int debug_log_pid, debug_log_fd; #endif static void *logger_thread(void *args) { - // Setup error handler - err_handler = exit_thread; - int log_fd = -1, log_pid; char line[4096]; @@ -50,9 +47,6 @@ static void *logger_thread(void *args) { } static void *magisk_log_thread(void *args) { - // Setup error handler - err_handler = exit_thread; - int have_data = 0; // Temp buffer for logs before we have data access @@ -95,9 +89,6 @@ static void *magisk_log_thread(void *args) { } static void *debug_magisk_log_thread(void *args) { - // Setup error handler - err_handler = exit_thread; - FILE *log = xfopen(DEBUG_LOG, "a"); setbuf(log, NULL); int pipefd[2]; diff --git a/jni/daemon/magisk.c b/jni/daemon/magisk.c index e33dfa685..f9108ec31 100644 --- a/jni/daemon/magisk.c +++ b/jni/daemon/magisk.c @@ -32,10 +32,6 @@ int create_links(const char *bin, const char *path) { return ret; } -// Global error hander function -// Should be changed each thread/process -__thread void (*err_handler)(void); - static void usage() { fprintf(stderr, "Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu) multi-call binary\n" @@ -72,8 +68,6 @@ static void usage() { int main(int argc, char *argv[]) { argv0 = argv[0]; - // Exit the whole app if error occurs by default - err_handler = exit_proc; char * arg = strrchr(argv[0], '/'); if (arg) ++arg; else arg = argv[0]; diff --git a/jni/include/logging.h b/jni/include/logging.h index 2738e7301..dc3418fa4 100644 --- a/jni/include/logging.h +++ b/jni/include/logging.h @@ -15,14 +15,6 @@ #define LOG_TAG "Magisk" -// Global handler for PLOGE -extern __thread void (*err_handler)(void); - -// Common error handlers -static inline void exit_proc() { exit(1); } -static inline void exit_thread() { pthread_exit(NULL); } -static inline void do_nothing() {} - #ifdef MAGISK_DEBUG #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) #else @@ -32,7 +24,7 @@ static inline void do_nothing() {} #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) -#define PLOGE(fmt, args...) { LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)); err_handler(); } +#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)) enum { HIDE_EVENT, diff --git a/jni/magiskhide/hide_utils.c b/jni/magiskhide/hide_utils.c index b34d5621c..249b81ef0 100644 --- a/jni/magiskhide/hide_utils.c +++ b/jni/magiskhide/hide_utils.c @@ -187,7 +187,6 @@ int destroy_list() { } void add_hide_list(int client) { - err_handler = do_nothing; char *proc = read_string(client); // ack write_int(client, add_list(proc)); @@ -195,7 +194,6 @@ void add_hide_list(int client) { } void rm_hide_list(int client) { - err_handler = do_nothing; char *proc = read_string(client); // ack write_int(client, rm_list(proc)); @@ -203,7 +201,6 @@ void rm_hide_list(int client) { } void ls_hide_list(int client) { - err_handler = do_nothing; if (!hideEnabled) { write_int(client, HIDE_NOT_ENABLED); return; diff --git a/jni/magiskhide/magiskhide.c b/jni/magiskhide/magiskhide.c index 7b45e7aa7..a38898979 100644 --- a/jni/magiskhide/magiskhide.c +++ b/jni/magiskhide/magiskhide.c @@ -41,9 +41,6 @@ static void usage(char *arg0) { } void launch_magiskhide(int client) { - // We manually handle crashes - err_handler = do_nothing; - if (hideEnabled) { if (client > 0) { write_int(client, HIDE_IS_ENABLED); diff --git a/jni/magiskhide/proc_monitor.c b/jni/magiskhide/proc_monitor.c index b357138a1..c48226b32 100644 --- a/jni/magiskhide/proc_monitor.c +++ b/jni/magiskhide/proc_monitor.c @@ -24,7 +24,6 @@ static int zygote_num, has_cache = 1, pipefd[2] = { -1, -1 }; // Workaround for the lack of pthread_cancel static void quit_pthread(int sig) { - err_handler = do_nothing; LOGD("proc_monitor: running cleanup\n"); destroy_list(); hideEnabled = 0; @@ -39,11 +38,6 @@ static void quit_pthread(int sig) { pthread_exit(NULL); } -static void proc_monitor_err() { - LOGE("proc_monitor: error occured, stopping magiskhide services\n"); - quit_pthread(SIGUSR1); -} - static int read_namespace(const int pid, char* target, const size_t size) { char path[32]; snprintf(path, sizeof(path), "/proc/%d/ns/mnt", pid); @@ -69,14 +63,8 @@ static void lazy_unmount(const char* mountpoint) { LOGD("hide_daemon: Unmount Failed (%s)\n", mountpoint); } -static void hide_daemon_err() { - LOGE("hide_daemon: error occured\n"); -} - static void hide_daemon(int pid) { LOGD("hide_daemon: start unmount for pid=[%d]\n", pid); - // When an error occurs, report its failure - err_handler = hide_daemon_err; char *line, buffer[PATH_MAX]; struct vector mount_list; @@ -152,15 +140,12 @@ void proc_monitor() { act.sa_handler = quit_pthread; sigaction(SIGUSR1, &act, NULL); - // The error handler should stop magiskhide services - err_handler = proc_monitor_err; - cache_block[0] = '\0'; // Get the mount namespace of init if (read_namespace(1, init_ns, 32)) { LOGE("proc_monitor: Your kernel doesn't support mount namespace :(\n"); - proc_monitor_err(); + quit_pthread(SIGUSR1); } LOGI("proc_monitor: init ns=%s\n", init_ns); diff --git a/jni/su b/jni/su index c912c192e..6de95e0d9 160000 --- a/jni/su +++ b/jni/su @@ -1 +1 @@ -Subproject commit c912c192e0d03119a14d7b772caa5d77bc4b7999 +Subproject commit 6de95e0d9bb6aa3e657a7e1492eed1b632c9f186 diff --git a/jni/utils/misc.c b/jni/utils/misc.c index 30dfbd626..b2bfe0cd4 100644 --- a/jni/utils/misc.c +++ b/jni/utils/misc.c @@ -243,9 +243,6 @@ static int v_exec_command(int err, int *fd, void (*setupenv)(struct vector*), co return pid; } - // Don't return to the daemon if anything goes wrong - err_handler = exit_proc; - if (fd) { xdup2(writeEnd, STDOUT_FILENO); if (err) xdup2(writeEnd, STDERR_FILENO);