Restart MagiskHide if daemon restarted

This commit is contained in:
topjohnwu 2017-10-10 19:49:15 +08:00
parent e645c6e465
commit 0327fd9710
6 changed files with 43 additions and 27 deletions

View File

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

View File

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

View File

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

View File

@ -7,6 +7,7 @@
#include <pthread.h>
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

View File

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

View File

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