From f31a24b16db557af46dac2b40fec6be532bd32d4 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 26 May 2018 23:14:09 +0800 Subject: [PATCH] Update setenv functions (also fixes uninstalling) --- native/jni/core/bootstages.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/native/jni/core/bootstages.c b/native/jni/core/bootstages.c index dc43210d3..81593426e 100644 --- a/native/jni/core/bootstages.c +++ b/native/jni/core/bootstages.c @@ -113,11 +113,11 @@ static struct node_entry *insert_child(struct node_entry *p, struct node_entry * * setenvs * ***********/ -static void bb_setenv(struct vector *v) { +static void set_path(struct vector *v) { for (int i = 0; environ[i]; ++i) { if (strncmp(environ[i], "PATH=", 5) == 0) { - snprintf(buf, PATH_MAX, "PATH=%s:%s", BBPATH, strchr(environ[i], '=') + 1); - vec_push_back(v, strdup(buf)); + vec_push_back(v, strdup("PATH=" BBPATH ":/sbin:" MIRRDIR "/system/bin:" + MIRRDIR "/system/xbin:" MIRRDIR "/vendor/bin")); } else { vec_push_back(v, strdup(environ[i])); } @@ -125,6 +125,11 @@ static void bb_setenv(struct vector *v) { vec_push_back(v, NULL); } +static void uninstall_env(struct vector *v) { + vec_push_back(v, strdup("BOOTMODE=true")); + set_path(v); +} + /*********** * Scripts * ***********/ @@ -143,7 +148,7 @@ static void exec_common_script(const char* stage) { if (access(buf2, X_OK) == -1) continue; LOGI("%s.d: exec [%s]\n", stage, entry->d_name); - int pid = exec_command(0, NULL, bb_setenv, "sh", buf2, NULL); + int pid = exec_command(0, NULL, set_path, "sh", buf2, NULL); if (pid != -1) waitpid(pid, NULL, 0); } @@ -160,7 +165,7 @@ static void exec_module_script(const char* stage) { if (access(buf2, F_OK) == -1 || access(buf, F_OK) == 0) continue; LOGI("%s: exec [%s.sh]\n", module, stage); - int pid = exec_command(0, NULL, bb_setenv, "sh", buf2, NULL); + int pid = exec_command(0, NULL, set_path, "sh", buf2, NULL); if (pid != -1) waitpid(pid, NULL, 0); } @@ -639,13 +644,12 @@ initialize: // uninstall if (access(UNINSTALLER, F_OK) == 0) { close(open(UNBLOCKFILE, O_RDONLY | O_CREAT)); - setenv("BOOTMODE", "true", 1); - exec_command(0, NULL, bb_setenv, "sh", UNINSTALLER, NULL); + exec_command(0, NULL, uninstall_env, "sh", UNINSTALLER, NULL); return; } // Start post-fs-data mode - execv("/sbin/magisk", (char *[]) { "magisk", "--post-fs-data", NULL }); + execl("/sbin/magisk", "magisk", "--post-fs-data", NULL); } void post_fs_data(int client) {