From 9c774f96db50477967b6b39aff5f1790e3b49cdb Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 28 May 2022 16:53:04 -0700 Subject: [PATCH] Use exec for boot_complete --- native/jni/core/bootstages.cpp | 6 ------ native/jni/core/magisk.cpp | 15 +++++++-------- native/jni/init/magiskrc.inc | 8 +------- native/jni/init/rootdir.cpp | 7 +++---- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index 077c0695b..5d80057a0 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -274,8 +274,6 @@ static pthread_mutex_t stage_lock = PTHREAD_MUTEX_INITIALIZER; extern int disable_deny(); void post_fs_data(int client) { - // ack - write_int(client, 0); close(client); mutex_guard lock(stage_lock); @@ -336,8 +334,6 @@ unblock_init: } void late_start(int client) { - // ack - write_int(client, 0); close(client); mutex_guard lock(stage_lock); @@ -354,8 +350,6 @@ void late_start(int client) { } void boot_complete(int client) { - // ack - write_int(client, 0); close(client); mutex_guard lock(stage_lock); diff --git a/native/jni/core/magisk.cpp b/native/jni/core/magisk.cpp index c669e92c5..cee5033f7 100644 --- a/native/jni/core/magisk.cpp +++ b/native/jni/core/magisk.cpp @@ -81,21 +81,20 @@ int magisk_main(int argc, char *argv[]) { cp_afc(argv[2], argv[3]); return 0; } else if (argv[1] == "--daemon"sv) { - int fd = connect_daemon(MainRequest::START_DAEMON, true); - close(fd); + close(connect_daemon(MainRequest::START_DAEMON, true)); return 0; } else if (argv[1] == "--stop"sv) { int fd = connect_daemon(MainRequest::STOP_DAEMON); return read_int(fd); } else if (argv[1] == "--post-fs-data"sv) { - int fd = connect_daemon(MainRequest::POST_FS_DATA, true); - return read_int(fd); + close(connect_daemon(MainRequest::POST_FS_DATA, true)); + return 0; } else if (argv[1] == "--service"sv) { - int fd = connect_daemon(MainRequest::LATE_START, true); - return read_int(fd); + close(connect_daemon(MainRequest::LATE_START, true)); + return 0; } else if (argv[1] == "--boot-complete"sv) { - int fd = connect_daemon(MainRequest::BOOT_COMPLETE, true); - return read_int(fd); + close(connect_daemon(MainRequest::BOOT_COMPLETE)); + return 0; } else if (argv[1] == "--denylist"sv) { return denylist_cli(argc - 1, argv + 1); } else if (argc >= 3 && argv[1] == "--sqlite"sv) { diff --git a/native/jni/init/magiskrc.inc b/native/jni/init/magiskrc.inc index 8c9b780c6..ae9771ecb 100644 --- a/native/jni/init/magiskrc.inc +++ b/native/jni/init/magiskrc.inc @@ -29,12 +29,6 @@ constexpr char MAGISK_RC[] = "\n" "on property:sys.boot_completed=1\n" -" start %4$s\n" -"\n" - -"service %4$s %1$s/magisk --boot-complete\n" -" user root\n" -" seclabel u:r:" SEPOL_PROC_DOMAIN ":s0\n" -" oneshot\n" +" exec %1$s/magisk --boot-complete\n" "\n" ; diff --git a/native/jni/init/rootdir.cpp b/native/jni/init/rootdir.cpp index aa2a6c253..759ba7284 100644 --- a/native/jni/init/rootdir.cpp +++ b/native/jni/init/rootdir.cpp @@ -51,12 +51,11 @@ static void patch_init_rc(const char *src, const char *dest, const char *tmp_dir rc_list.clear(); // Inject Magisk rc scripts - char pfd_svc[16], ls_svc[16], bc_svc[16]; + char pfd_svc[16], ls_svc[16]; gen_rand_str(pfd_svc, sizeof(pfd_svc)); gen_rand_str(ls_svc, sizeof(ls_svc)); - gen_rand_str(bc_svc, sizeof(bc_svc)); - LOGD("Inject magisk services: [%s] [%s] [%s]\n", pfd_svc, ls_svc, bc_svc); - fprintf(rc, MAGISK_RC, tmp_dir, pfd_svc, ls_svc, bc_svc); + LOGD("Inject magisk services: [%s] [%s]\n", pfd_svc, ls_svc); + fprintf(rc, MAGISK_RC, tmp_dir, pfd_svc, ls_svc); fclose(rc); clone_attr(src, dest);