From c0447009db3a108f109784cad66abfcb88a98bd3 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 16 Mar 2019 04:45:56 -0400 Subject: [PATCH] Allow entrypoint for rootfs construction simulation --- native/jni/core/init.cpp | 15 +++++++++++++-- native/jni/include/magisk.h | 1 - 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/native/jni/core/init.cpp b/native/jni/core/init.cpp index 518d4ee6e..2504cff76 100644 --- a/native/jni/core/init.cpp +++ b/native/jni/core/init.cpp @@ -53,7 +53,12 @@ #define DEFAULT_DT_DIR "/proc/device-tree/firmware/android" -int (*init_applet_main[])(int, char *[]) = { magiskpolicy_main, magiskpolicy_main, nullptr }; +static int test_main(int argc, char *argv[]); + +constexpr const char *init_applet[] = + { "magiskpolicy", "supolicy", "init_test", nullptr }; +constexpr int (*init_applet_main[])(int, char *[]) = + { magiskpolicy_main, magiskpolicy_main, test_main, nullptr }; struct cmdline { bool system_as_root; @@ -597,7 +602,7 @@ void MagiskInit::test() { cmdline_logging(); log_cb.ex = nop_ex; - chdir(argv[1]); + chdir(dirname(argv[0])); chroot("."); chdir("/"); @@ -608,6 +613,12 @@ void MagiskInit::test() { cleanup(); } +static int test_main(int argc, char *argv[]) { + MagiskInit init(argv); + init.test(); + return 0; +} + int main(int argc, char *argv[]) { umask(0); diff --git a/native/jni/include/magisk.h b/native/jni/include/magisk.h index 74bedcd1c..1c2ec3460 100644 --- a/native/jni/include/magisk.h +++ b/native/jni/include/magisk.h @@ -29,7 +29,6 @@ extern int SDK_INT; constexpr const char *applet_names[] = { "magisk", "su", "resetprop", "magiskhide", nullptr }; -constexpr const char *init_applet[] = { "magiskpolicy", "supolicy", nullptr }; // Multi-call entrypoints int magisk_main(int argc, char *argv[]);