Update setenv functions (also fixes uninstalling)

This commit is contained in:
topjohnwu 2018-05-26 23:14:09 +08:00
parent b436bce565
commit f31a24b16d

View File

@ -113,11 +113,11 @@ static struct node_entry *insert_child(struct node_entry *p, struct node_entry *
* setenvs * * setenvs *
***********/ ***********/
static void bb_setenv(struct vector *v) { static void set_path(struct vector *v) {
for (int i = 0; environ[i]; ++i) { for (int i = 0; environ[i]; ++i) {
if (strncmp(environ[i], "PATH=", 5) == 0) { if (strncmp(environ[i], "PATH=", 5) == 0) {
snprintf(buf, PATH_MAX, "PATH=%s:%s", BBPATH, strchr(environ[i], '=') + 1); vec_push_back(v, strdup("PATH=" BBPATH ":/sbin:" MIRRDIR "/system/bin:"
vec_push_back(v, strdup(buf)); MIRRDIR "/system/xbin:" MIRRDIR "/vendor/bin"));
} else { } else {
vec_push_back(v, strdup(environ[i])); vec_push_back(v, strdup(environ[i]));
} }
@ -125,6 +125,11 @@ static void bb_setenv(struct vector *v) {
vec_push_back(v, NULL); vec_push_back(v, NULL);
} }
static void uninstall_env(struct vector *v) {
vec_push_back(v, strdup("BOOTMODE=true"));
set_path(v);
}
/*********** /***********
* Scripts * * Scripts *
***********/ ***********/
@ -143,7 +148,7 @@ static void exec_common_script(const char* stage) {
if (access(buf2, X_OK) == -1) if (access(buf2, X_OK) == -1)
continue; continue;
LOGI("%s.d: exec [%s]\n", stage, entry->d_name); 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) if (pid != -1)
waitpid(pid, NULL, 0); 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) if (access(buf2, F_OK) == -1 || access(buf, F_OK) == 0)
continue; continue;
LOGI("%s: exec [%s.sh]\n", module, stage); 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) if (pid != -1)
waitpid(pid, NULL, 0); waitpid(pid, NULL, 0);
} }
@ -639,13 +644,12 @@ initialize:
// uninstall // uninstall
if (access(UNINSTALLER, F_OK) == 0) { if (access(UNINSTALLER, F_OK) == 0) {
close(open(UNBLOCKFILE, O_RDONLY | O_CREAT)); close(open(UNBLOCKFILE, O_RDONLY | O_CREAT));
setenv("BOOTMODE", "true", 1); exec_command(0, NULL, uninstall_env, "sh", UNINSTALLER, NULL);
exec_command(0, NULL, bb_setenv, "sh", UNINSTALLER, NULL);
return; return;
} }
// Start post-fs-data mode // 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) { void post_fs_data(int client) {