diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index 1c732bd0d..547cc3f6c 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -268,8 +268,7 @@ void post_fs_data(int client) { foreach_modules("disable"); stop_magiskhide(); } else { - LOGI("* Running post-fs-data.d scripts\n"); - exec_common_script("post-fs-data"); + exec_common_scripts("post-fs-data"); auto_start_magiskhide(); handle_modules(); } @@ -299,15 +298,8 @@ void late_start(int client) { if (!pfs_done || safe_mode) return; - LOGI("* Running service.d scripts\n"); - exec_common_script("service"); - - LOGI("* Running module service scripts\n"); - exec_module_script("service", module_list); - - // All boot stage done, cleanup - module_list.clear(); - module_list.shrink_to_fit(); + exec_common_scripts("service"); + exec_module_scripts("service"); } void boot_complete(int client) { diff --git a/native/jni/core/module.cpp b/native/jni/core/module.cpp index 8c55ef564..e4bf3e4c3 100644 --- a/native/jni/core/module.cpp +++ b/native/jni/core/module.cpp @@ -25,7 +25,7 @@ using namespace std; #define TYPE_CUSTOM (1 << 5) /* custom node type overrides all */ #define TYPE_DIR (TYPE_INTER|TYPE_SKEL|TYPE_ROOT) -vector module_list; +static vector module_list; class node_entry; class dir_node; @@ -671,10 +671,7 @@ static void collect_modules() { void handle_modules() { prepare_modules(); collect_modules(); - - // Execute module scripts - LOGI("* Running module post-fs-data scripts\n"); - exec_module_script("post-fs-data", module_list); + exec_module_scripts("post-fs-data"); // Recollect modules (module scripts could remove itself) module_list.clear(); @@ -699,3 +696,7 @@ void foreach_modules(const char *name) { } } } + +void exec_module_scripts(const char *stage) { + exec_module_scripts(stage, module_list); +} diff --git a/native/jni/core/scripting.cpp b/native/jni/core/scripting.cpp index a022a3e28..7afdea62c 100644 --- a/native/jni/core/scripting.cpp +++ b/native/jni/core/scripting.cpp @@ -24,7 +24,8 @@ void exec_script(const char *script) { exec_command_sync(exec, BBEXEC_CMD, script); } -void exec_common_script(const char *stage) { +void exec_common_scripts(const char *stage) { + LOGI("* Running %s.d scripts\n", stage); char path[4096]; char *name = path + sprintf(path, SECURE_DIR "/%s.d", stage); auto dir = xopen_dir(path); @@ -53,7 +54,8 @@ void exec_common_script(const char *stage) { } } -void exec_module_script(const char *stage, const vector &module_list) { +void exec_module_scripts(const char *stage, const vector &module_list) { + LOGI("* Running module %s scripts\n", stage); char path[4096]; bool pfs = stage == "post-fs-data"sv; for (auto &m : module_list) { diff --git a/native/jni/include/daemon.hpp b/native/jni/include/daemon.hpp index 8ab65d143..a3fc7e6d7 100644 --- a/native/jni/include/daemon.hpp +++ b/native/jni/include/daemon.hpp @@ -42,22 +42,23 @@ extern bool RECOVERY_MODE; extern int DAEMON_STATE; #define APP_DATA_DIR (SDK_INT >= 24 ? "/data/user_de" : "/data/user") -extern std::vector module_list; - // Daemon handlers void post_fs_data(int client); void late_start(int client); void boot_complete(int client); void magiskhide_handler(int client); -void su_daemon_handler(int client, struct ucred *credential); -void foreach_modules(const char *name); +void su_daemon_handler(int client, ucred *credential); // Misc int connect_daemon(bool create = false); void unlock_blocks(); +void reboot(); + +// Module stuffs void handle_modules(); void magic_mount(); -void reboot(); +void foreach_modules(const char *name); +void exec_module_scripts(const char *stage); // MagiskHide void auto_start_magiskhide(); @@ -65,6 +66,6 @@ int stop_magiskhide(); // Scripting void exec_script(const char *script); -void exec_common_script(const char *stage); -void exec_module_script(const char *stage, const std::vector &module_list); +void exec_common_scripts(const char *stage); +void exec_module_scripts(const char *stage, const std::vector &module_list); void install_apk(const char *apk);