Remove err_handler

This commit is contained in:
topjohnwu 2017-10-13 22:25:16 +08:00
parent 2a8898e7c3
commit cddeaffada
10 changed files with 3 additions and 62 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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];

View File

@ -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];

View File

@ -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,

View File

@ -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;

View File

@ -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);

View File

@ -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);

2
jni/su

@ -1 +1 @@
Subproject commit c912c192e0d03119a14d7b772caa5d77bc4b7999
Subproject commit 6de95e0d9bb6aa3e657a7e1492eed1b632c9f186

View File

@ -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);