From d9564bd04ce46b7a36398e072db30389a21a73f6 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 2 Aug 2018 05:35:01 +0800 Subject: [PATCH] Delay full sepolicy patch loading time --- native/jni/core/bootstages.c | 11 ++++++++--- native/jni/include/magisk.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/native/jni/core/bootstages.c b/native/jni/core/bootstages.c index ef1d855e8..02da85963 100644 --- a/native/jni/core/bootstages.c +++ b/native/jni/core/bootstages.c @@ -678,7 +678,8 @@ void post_fs_data(int client) { LOGI("** post-fs-data mode running\n"); xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL); - full_patch_pid = exec_command(0, NULL, NULL, "/sbin/magiskpolicy", "--live", "allow "SEPOL_PROC_DOMAIN" * * *", NULL); + full_patch_pid = exec_command(0, NULL, NULL, + "/sbin/magiskpolicy", "--save", TMPSEPOLICY, "allow "SEPOL_PROC_DOMAIN" * * *", NULL); // Allocate buffer buf = xmalloc(PATH_MAX); @@ -803,9 +804,13 @@ void late_start(int client) { if (buf == NULL) buf = xmalloc(PATH_MAX); if (buf2 == NULL) buf2 = xmalloc(PATH_MAX); - // Wait till the full patch is done - if (full_patch_pid > 0) + if (full_patch_pid > 0) { + // Wait till the full patch is done waitpid(full_patch_pid, NULL, 0); + // Load the policy + exec_command_sync("/sbin/magiskpolicy", "--live", "--load", TMPSEPOLICY, NULL); + unlink(TMPSEPOLICY); + } // Run scripts after full patch, most reliable way to run scripts LOGI("* Running service.d scripts\n"); diff --git a/native/jni/include/magisk.h b/native/jni/include/magisk.h index f44431be2..19f4f01bb 100644 --- a/native/jni/include/magisk.h +++ b/native/jni/include/magisk.h @@ -17,6 +17,7 @@ #define LOGFILE "/cache/magisk.log" #define UNBLOCKFILE "/dev/.magisk.unblock" +#define TMPSEPOLICY "/dev/.tmp_sepolicy" #define DISABLEFILE "/cache/.disable_magisk" #define MAGISKTMP "/sbin/.core" #define BLOCKDIR MAGISKTMP "/block"