mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-16 21:53:04 +00:00
Adjust run_command
This commit is contained in:
@@ -15,7 +15,7 @@ static int e2fsck(const char *img) {
|
||||
char buffer[128];
|
||||
int pid, fd = -1;
|
||||
char *const command[] = { "e2fsck", "-yf", (char *) img, NULL };
|
||||
pid = run_command(1, &fd, NULL, "/system/bin/e2fsck", command);
|
||||
pid = run_command2(1, &fd, NULL, command);
|
||||
if (pid < 0)
|
||||
return 1;
|
||||
while (fdgets(buffer, sizeof(buffer), fd))
|
||||
@@ -63,7 +63,7 @@ int create_img(const char *img, int size) {
|
||||
char buffer[16];
|
||||
snprintf(buffer, sizeof(buffer), "%dM", size);
|
||||
char *const command[] = { "make_ext4fs", "-l", buffer, "-a", "/magisk", "-S", filename, (char *) img, NULL };
|
||||
pid = run_command(0, NULL, NULL, "/system/bin/make_ext4fs", command);
|
||||
pid = run_command2(0, NULL, NULL, command);
|
||||
if (pid < 0)
|
||||
return 1;
|
||||
waitpid(pid, &status, 0);
|
||||
@@ -77,7 +77,7 @@ int get_img_size(const char *img, int *used, int *total) {
|
||||
char buffer[PATH_MAX];
|
||||
int pid, fd = -1, status = 1;
|
||||
char *const command[] = { "e2fsck", "-n", (char *) img, NULL };
|
||||
pid = run_command(1, &fd, NULL, "/system/bin/e2fsck", command);
|
||||
pid = run_command2(1, &fd, NULL, command);
|
||||
if (pid < 0)
|
||||
return 1;
|
||||
while (fdgets(buffer, sizeof(buffer), fd)) {
|
||||
@@ -110,7 +110,7 @@ int resize_img(const char *img, int size) {
|
||||
int pid, status, fd = -1;
|
||||
snprintf(buffer, sizeof(buffer), "%dM", size);
|
||||
char *const command[] = { "resize2fs", (char *) img, buffer, NULL };
|
||||
pid = run_command(1, &fd, NULL, "/system/bin/resize2fs", command);
|
||||
pid = run_command2(1, &fd, NULL, command);
|
||||
if (pid < 0)
|
||||
return 1;
|
||||
while (fdgets(buffer, sizeof(buffer), fd))
|
||||
|
@@ -219,13 +219,22 @@ void setup_sighandlers(void (*handler)(int)) {
|
||||
}
|
||||
}
|
||||
|
||||
int run_command(char *const argv[]) {
|
||||
int pid = run_command2(0, NULL, NULL, argv);
|
||||
if (pid != -1)
|
||||
waitpid(pid, NULL, 0);
|
||||
else
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
fd == NULL -> Ignore output
|
||||
*fd < 0 -> Open pipe and set *fd to the read end
|
||||
*fd >= 0 -> STDOUT (or STDERR) will be redirected to *fd
|
||||
*cb -> A callback function which runs after fork
|
||||
*/
|
||||
int run_command(int err, int *fd, void (*cb)(void), const char *path, char *const argv[]) {
|
||||
int run_command2(int err, int *fd, void (*cb)(void), char *const argv[]) {
|
||||
int pipefd[2], writeEnd = -1;
|
||||
|
||||
if (fd) {
|
||||
@@ -255,7 +264,7 @@ int run_command(int err, int *fd, void (*cb)(void), const char *path, char *cons
|
||||
if (err) xdup2(writeEnd, STDERR_FILENO);
|
||||
}
|
||||
|
||||
execv(path, argv);
|
||||
execvp(argv[0], argv);
|
||||
PLOGE("execv");
|
||||
return -1;
|
||||
}
|
||||
@@ -359,13 +368,12 @@ int clone_dir(const char *source, const char *target) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rm_rf(const char *target) {
|
||||
void rm_rf(const char *target) {
|
||||
if (access(target, F_OK) == -1)
|
||||
return 0;
|
||||
return;
|
||||
// Use external rm command, saves a lot of headache and issues
|
||||
char command[PATH_MAX];
|
||||
snprintf(command, sizeof(command), "rm -rf %s", target);
|
||||
return system(command);
|
||||
char *const command[] = { "rm", "-rf", (char*) target, NULL };
|
||||
run_command(command);
|
||||
}
|
||||
|
||||
void clone_attr(const char *source, const char *target) {
|
||||
|
Reference in New Issue
Block a user