Migrate exec function to C++ arrays

This commit is contained in:
topjohnwu
2018-11-03 04:03:11 -04:00
parent 6339ba6bfb
commit 4351de503f
6 changed files with 90 additions and 112 deletions

View File

@@ -115,29 +115,15 @@ static struct node_entry *insert_child(struct node_entry *p, struct node_entry *
* setenvs *
***********/
static void set_path(struct vector *v) {
static void set_path() {
char buffer[512];
for (int i = 0; environ[i]; ++i) {
if (strncmp(environ[i], "PATH=", 5) == 0) {
sprintf(buffer, "PATH="BBPATH":%s", environ[i] + 5);
vec_push_back(v, strdup(buffer));
} else {
vec_push_back(v, strdup(environ[i]));
}
}
vec_push_back(v, NULL);
sprintf(buffer, BBPATH ":%s", getenv("PATH"));
setenv("PATH", buffer, 1);
}
static void set_mirror_path(struct vector *v) {
for (int i = 0; environ[i]; ++i) {
if (strncmp(environ[i], "PATH=", 5) == 0) {
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]));
}
}
vec_push_back(v, NULL);
static void set_mirror_path() {
setenv("PATH", BBPATH ":/sbin:" MIRRDIR "/system/bin:"
MIRRDIR "/system/xbin:" MIRRDIR "/vendor/bin", 1);
}
/***********

View File

@@ -82,7 +82,7 @@ static void *logcat_thread(void *args) {
char line[4096];
while (1) {
// Start logcat
log_pid = exec_array(0, &log_fd, NULL, (char **) vec_entry(&log_cmd));
log_pid = exec_array(0, &log_fd, NULL, (const char **) vec_entry(&log_cmd));
FILE *logs = fdopen(log_fd, "r");
while (fgets(line, sizeof(line), logs)) {
if (line[0] == '-')
@@ -103,7 +103,7 @@ static void *logcat_thread(void *args) {
LOGI("magisklogd: logcat output EOF");
// Clear buffer
log_pid = exec_array(0, NULL, NULL, (char **) vec_entry(&clear_cmd));
log_pid = exec_array(0, NULL, NULL, (const char **) vec_entry(&clear_cmd));
waitpid(log_pid, NULL, 0);
}
}