Add busybox into PATH for scripts

This commit is contained in:
topjohnwu
2017-08-01 15:34:16 +08:00
parent 10c8ea17aa
commit 5fab15fee5
7 changed files with 56 additions and 27 deletions

View File

@@ -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, "/system/bin/e2fsck", command);
pid = run_command(1, &fd, NULL, "/system/bin/e2fsck", 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, "/system/bin/make_ext4fs", command);
pid = run_command(0, NULL, NULL, "/system/bin/make_ext4fs", 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, "/system/bin/e2fsck", command);
pid = run_command(1, &fd, NULL, "/system/bin/e2fsck", 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, "/system/bin/resize2fs", command);
pid = run_command(1, &fd, NULL, "/system/bin/resize2fs", command);
if (pid < 0)
return 1;
while (fdgets(buffer, sizeof(buffer), fd))

View File

@@ -223,8 +223,9 @@ void setup_sighandlers(void (*handler)(int)) {
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, const char *path, char *const argv[]) {
int run_command(int err, int *fd, void (*cb)(void), const char *path, char *const argv[]) {
int pipefd[2], writeEnd = -1;
if (fd) {
@@ -247,6 +248,8 @@ int run_command(int err, int *fd, const char *path, char *const argv[]) {
return pid;
}
if (cb) cb();
if (fd) {
xdup2(writeEnd, STDOUT_FILENO);
if (err) xdup2(writeEnd, STDERR_FILENO);
@@ -406,3 +409,11 @@ int switch_mnt_ns(int pid) {
close(fd);
return ret;
}
void link_busybox() {
mkdir_p(BBPATH, 0755);
char *const command[] = { "busybox", "--install", "-s", BBPATH, NULL};
int pid = run_command(0, NULL, NULL, BBBIN, command);
if (pid != -1)
waitpid(pid, NULL, 0);
}