From 8de03eef3fc4e9c7bd3f247ace36c0826d3be0e5 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 23 Mar 2019 03:50:55 -0400 Subject: [PATCH] Allow modules to have custom uninstaller script --- native/jni/core/bootstages.cpp | 3 +++ native/jni/core/scripting.cpp | 8 ++++++++ native/jni/include/daemon.h | 1 + 3 files changed, 12 insertions(+) diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index 046b35324..453202fa8 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -482,6 +482,9 @@ static void collect_modules() { if (access("remove", F_OK) == 0) { chdir(".."); LOGI("%s: remove\n", entry->d_name); + sprintf(buf, "%s/uninstall.sh", entry->d_name); + if (access(buf, F_OK) == 0) + exec_script(buf); rm_rf(entry->d_name); continue; } diff --git a/native/jni/core/scripting.cpp b/native/jni/core/scripting.cpp index 2e4f9d1b8..2ae0f7547 100644 --- a/native/jni/core/scripting.cpp +++ b/native/jni/core/scripting.cpp @@ -16,6 +16,14 @@ static void set_path() { setenv("PATH", buf, 1); } +void exec_script(const char *script) { + exec_t exec { + .pre_exec = set_path, + .fork = fork_no_zombie + }; + exec_command_sync(exec, "/system/bin/sh", script); +} + void exec_common_script(const char *stage) { char path[4096]; DIR *dir; diff --git a/native/jni/include/daemon.h b/native/jni/include/daemon.h index f8edcd5b0..637a7a6c2 100644 --- a/native/jni/include/daemon.h +++ b/native/jni/include/daemon.h @@ -69,6 +69,7 @@ void boot_complete(int client); * 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 migrate_img(const char *img);