From fe644e10d0244250379ea726359597034d949706 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 17 Sep 2019 00:21:07 -0400 Subject: [PATCH] Make sure post-fs-data is first ran Close #1601 --- native/jni/core/bootstages.cpp | 8 ++++++++ native/jni/core/daemon.cpp | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index a848f967d..54e3c5ca7 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -22,6 +22,7 @@ using namespace std; static char buf[PATH_MAX], buf2[PATH_MAX]; static vector module_list; static bool no_secure_dir = false; +static bool pfs_done = false; static int bind_mount(const char *from, const char *to, bool log = true); extern void auto_start_magiskhide(); @@ -600,6 +601,7 @@ static void dump_logs() { } [[noreturn]] static void core_only() { + pfs_done = true; auto_start_magiskhide(); unblock_boot_process(); } @@ -714,6 +716,9 @@ void late_start(int client) { reboot(); } + if (!pfs_done) + return; + if (access(BBPATH, F_OK) != 0){ LOGE("* post-fs-data mode is not triggered\n"); unlock_blocks(); @@ -745,6 +750,9 @@ void boot_complete(int client) { write_int(client, 0); close(client); + if (!pfs_done) + return; + if (access(MANAGERAPK, F_OK) == 0) { // Install Magisk Manager if exists rename(MANAGERAPK, "/data/magisk.apk"); diff --git a/native/jni/core/daemon.cpp b/native/jni/core/daemon.cpp index 274c41675..4ccb562fe 100644 --- a/native/jni/core/daemon.cpp +++ b/native/jni/core/daemon.cpp @@ -18,14 +18,14 @@ int SDK_INT = -1; bool RECOVERY_MODE = false; -static struct stat SERVER_STAT; +static struct stat self_st; static void verify_client(int client, pid_t pid) { // Verify caller is the same as server char path[32]; sprintf(path, "/proc/%d/exe", pid); struct stat st; - if (stat(path, &st) || st.st_dev != SERVER_STAT.st_dev || st.st_ino != SERVER_STAT.st_ino) { + if (stat(path, &st) || st.st_dev != self_st.st_dev || st.st_ino != self_st.st_ino) { close(client); pthread_exit(nullptr); } @@ -137,7 +137,7 @@ static void main_daemon() { LOGI(SHOW_VER(Magisk) " daemon started\n"); // Get server stat - stat("/proc/self/exe", &SERVER_STAT); + stat("/proc/self/exe", &self_st); // Get API level parse_prop_file("/system/build.prop", [](auto key, auto val) -> bool {