Loading fs_mgr/fs_mgr.c +5 −4 Original line number Original line Diff line number Diff line Loading @@ -152,7 +152,7 @@ static void check_fs(char *blk_device, char *fs_type, char *target) ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), e2fsck_argv, ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), e2fsck_argv, &status, true, LOG_KLOG | LOG_FILE, &status, true, LOG_KLOG | LOG_FILE, true, FSCK_LOG_FILE); true, FSCK_LOG_FILE, NULL, 0); if (ret < 0) { if (ret < 0) { /* No need to check for error in fork, we can't really handle it now */ /* No need to check for error in fork, we can't really handle it now */ Loading @@ -169,7 +169,7 @@ static void check_fs(char *blk_device, char *fs_type, char *target) ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv, ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv, &status, true, LOG_KLOG | LOG_FILE, &status, true, LOG_KLOG | LOG_FILE, true, FSCK_LOG_FILE); true, FSCK_LOG_FILE, NULL, 0); if (ret < 0) { if (ret < 0) { /* No need to check for error in fork, we can't really handle it now */ /* No need to check for error in fork, we can't really handle it now */ ERROR("Failed trying to run %s\n", F2FS_FSCK_BIN); ERROR("Failed trying to run %s\n", F2FS_FSCK_BIN); Loading Loading @@ -795,7 +795,8 @@ int fs_mgr_swapon_all(struct fstab *fstab) /* Initialize the swap area */ /* Initialize the swap area */ mkswap_argv[1] = fstab->recs[i].blk_device; mkswap_argv[1] = fstab->recs[i].blk_device; err = android_fork_execvp_ext(ARRAY_SIZE(mkswap_argv), mkswap_argv, err = android_fork_execvp_ext(ARRAY_SIZE(mkswap_argv), mkswap_argv, &status, true, LOG_KLOG, false, NULL); &status, true, LOG_KLOG, false, NULL, NULL, 0); if (err) { if (err) { ERROR("mkswap failed for %s\n", fstab->recs[i].blk_device); ERROR("mkswap failed for %s\n", fstab->recs[i].blk_device); ret = -1; ret = -1; Loading init/builtins.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -150,13 +150,13 @@ static void unmount_and_fsck(const struct mntent *entry) "/system/bin/fsck.f2fs", "-f", entry->mnt_fsname, "/system/bin/fsck.f2fs", "-f", entry->mnt_fsname, }; }; android_fork_execvp_ext(ARRAY_SIZE(f2fs_argv), (char **)f2fs_argv, android_fork_execvp_ext(ARRAY_SIZE(f2fs_argv), (char **)f2fs_argv, &st, true, LOG_KLOG, true, NULL); &st, true, LOG_KLOG, true, NULL, NULL, 0); } else if (!strcmp(entry->mnt_type, "ext4")) { } else if (!strcmp(entry->mnt_type, "ext4")) { const char *ext4_argv[] = { const char *ext4_argv[] = { "/system/bin/e2fsck", "-f", "-y", entry->mnt_fsname, "/system/bin/e2fsck", "-f", "-y", entry->mnt_fsname, }; }; android_fork_execvp_ext(ARRAY_SIZE(ext4_argv), (char **)ext4_argv, android_fork_execvp_ext(ARRAY_SIZE(ext4_argv), (char **)ext4_argv, &st, true, LOG_KLOG, true, NULL); &st, true, LOG_KLOG, true, NULL, NULL, 0); } } } } Loading logwrapper/include/logwrap/logwrap.h +21 −2 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ #define __LIBS_LOGWRAP_H #define __LIBS_LOGWRAP_H #include <stdbool.h> #include <stdbool.h> #include <stdint.h> __BEGIN_DECLS __BEGIN_DECLS Loading Loading @@ -53,6 +54,9 @@ __BEGIN_DECLS * the specified log until the child has exited. * the specified log until the child has exited. * file_path: if log_target has the LOG_FILE bit set, then this parameter * file_path: if log_target has the LOG_FILE bit set, then this parameter * must be set to the pathname of the file to log to. * must be set to the pathname of the file to log to. * opts: set to non-NULL if you want to use one or more of the * FORK_EXECVP_OPTION_* features. * opts_len: the length of the opts array. When opts is NULL, pass 0. * * * Return value: * Return value: * 0 when logwrap successfully run the child process and captured its status * 0 when logwrap successfully run the child process and captured its status Loading @@ -68,8 +72,22 @@ __BEGIN_DECLS #define LOG_KLOG 2 #define LOG_KLOG 2 #define LOG_FILE 4 #define LOG_FILE 4 /* Write data to child's stdin. */ #define FORK_EXECVP_OPTION_INPUT 0 struct AndroidForkExecvpOption { int opt_type; union { struct { const uint8_t* input; size_t input_len; } opt_input; }; }; int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int_quit, int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int_quit, int log_target, bool abbreviated, char *file_path); int log_target, bool abbreviated, char *file_path, const struct AndroidForkExecvpOption* opts, size_t opts_len); /* Similar to above, except abbreviated logging is not available, and if logwrap /* Similar to above, except abbreviated logging is not available, and if logwrap * is true, logging is to the Android system log, and if false, there is no * is true, logging is to the Android system log, and if false, there is no Loading @@ -79,7 +97,8 @@ static inline int android_fork_execvp(int argc, char* argv[], int *status, bool ignore_int_quit, bool logwrap) bool ignore_int_quit, bool logwrap) { { return android_fork_execvp_ext(argc, argv, status, ignore_int_quit, return android_fork_execvp_ext(argc, argv, status, ignore_int_quit, (logwrap ? LOG_ALOG : LOG_NONE), false, NULL); (logwrap ? LOG_ALOG : LOG_NONE), false, NULL, NULL, 0); } } __END_DECLS __END_DECLS Loading logwrapper/logwrap.c +26 −2 Original line number Original line Diff line number Diff line Loading @@ -474,7 +474,8 @@ static void child(int argc, char* argv[]) { } } int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int_quit, int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int_quit, int log_target, bool abbreviated, char *file_path) { int log_target, bool abbreviated, char *file_path, const struct AndroidForkExecvpOption* opts, size_t opts_len) { pid_t pid; pid_t pid; int parent_ptty; int parent_ptty; int child_ptty; int child_ptty; Loading @@ -483,6 +484,7 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int sigset_t blockset; sigset_t blockset; sigset_t oldset; sigset_t oldset; int rc = 0; int rc = 0; size_t i; rc = pthread_mutex_lock(&fd_mutex); rc = pthread_mutex_lock(&fd_mutex); if (rc) { if (rc) { Loading Loading @@ -529,7 +531,13 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int pthread_sigmask(SIG_SETMASK, &oldset, NULL); pthread_sigmask(SIG_SETMASK, &oldset, NULL); close(parent_ptty); close(parent_ptty); // redirect stdout and stderr // redirect stdin, stdout and stderr for (i = 0; i < opts_len; ++i) { if (opts[i].opt_type == FORK_EXECVP_OPTION_INPUT) { dup2(child_ptty, 0); break; } } dup2(child_ptty, 1); dup2(child_ptty, 1); dup2(child_ptty, 2); dup2(child_ptty, 2); close(child_ptty); close(child_ptty); Loading @@ -546,6 +554,22 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int sigaction(SIGQUIT, &ignact, &quitact); sigaction(SIGQUIT, &ignact, &quitact); } } for (i = 0; i < opts_len; ++i) { if (opts[i].opt_type == FORK_EXECVP_OPTION_INPUT) { size_t left = opts[i].opt_input.input_len; const uint8_t* input = opts[i].opt_input.input; while (left > 0) { ssize_t res = TEMP_FAILURE_RETRY(write(parent_ptty, input, left)); if (res < 0) { break; } left -= res; input += res; } } } rc = parent(argv[0], parent_ptty, pid, status, log_target, rc = parent(argv[0], parent_ptty, pid, status, log_target, abbreviated, file_path); abbreviated, file_path); } } Loading logwrapper/logwrapper.c +1 −1 Original line number Original line Diff line number Diff line Loading @@ -81,7 +81,7 @@ int main(int argc, char* argv[]) { } } rc = android_fork_execvp_ext(argc, &argv[0], &status, true, rc = android_fork_execvp_ext(argc, &argv[0], &status, true, log_target, abbreviated, NULL); log_target, abbreviated, NULL, NULL, 0); if (!rc) { if (!rc) { if (WIFEXITED(status)) if (WIFEXITED(status)) rc = WEXITSTATUS(status); rc = WEXITSTATUS(status); Loading Loading
fs_mgr/fs_mgr.c +5 −4 Original line number Original line Diff line number Diff line Loading @@ -152,7 +152,7 @@ static void check_fs(char *blk_device, char *fs_type, char *target) ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), e2fsck_argv, ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), e2fsck_argv, &status, true, LOG_KLOG | LOG_FILE, &status, true, LOG_KLOG | LOG_FILE, true, FSCK_LOG_FILE); true, FSCK_LOG_FILE, NULL, 0); if (ret < 0) { if (ret < 0) { /* No need to check for error in fork, we can't really handle it now */ /* No need to check for error in fork, we can't really handle it now */ Loading @@ -169,7 +169,7 @@ static void check_fs(char *blk_device, char *fs_type, char *target) ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv, ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv, &status, true, LOG_KLOG | LOG_FILE, &status, true, LOG_KLOG | LOG_FILE, true, FSCK_LOG_FILE); true, FSCK_LOG_FILE, NULL, 0); if (ret < 0) { if (ret < 0) { /* No need to check for error in fork, we can't really handle it now */ /* No need to check for error in fork, we can't really handle it now */ ERROR("Failed trying to run %s\n", F2FS_FSCK_BIN); ERROR("Failed trying to run %s\n", F2FS_FSCK_BIN); Loading Loading @@ -795,7 +795,8 @@ int fs_mgr_swapon_all(struct fstab *fstab) /* Initialize the swap area */ /* Initialize the swap area */ mkswap_argv[1] = fstab->recs[i].blk_device; mkswap_argv[1] = fstab->recs[i].blk_device; err = android_fork_execvp_ext(ARRAY_SIZE(mkswap_argv), mkswap_argv, err = android_fork_execvp_ext(ARRAY_SIZE(mkswap_argv), mkswap_argv, &status, true, LOG_KLOG, false, NULL); &status, true, LOG_KLOG, false, NULL, NULL, 0); if (err) { if (err) { ERROR("mkswap failed for %s\n", fstab->recs[i].blk_device); ERROR("mkswap failed for %s\n", fstab->recs[i].blk_device); ret = -1; ret = -1; Loading
init/builtins.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -150,13 +150,13 @@ static void unmount_and_fsck(const struct mntent *entry) "/system/bin/fsck.f2fs", "-f", entry->mnt_fsname, "/system/bin/fsck.f2fs", "-f", entry->mnt_fsname, }; }; android_fork_execvp_ext(ARRAY_SIZE(f2fs_argv), (char **)f2fs_argv, android_fork_execvp_ext(ARRAY_SIZE(f2fs_argv), (char **)f2fs_argv, &st, true, LOG_KLOG, true, NULL); &st, true, LOG_KLOG, true, NULL, NULL, 0); } else if (!strcmp(entry->mnt_type, "ext4")) { } else if (!strcmp(entry->mnt_type, "ext4")) { const char *ext4_argv[] = { const char *ext4_argv[] = { "/system/bin/e2fsck", "-f", "-y", entry->mnt_fsname, "/system/bin/e2fsck", "-f", "-y", entry->mnt_fsname, }; }; android_fork_execvp_ext(ARRAY_SIZE(ext4_argv), (char **)ext4_argv, android_fork_execvp_ext(ARRAY_SIZE(ext4_argv), (char **)ext4_argv, &st, true, LOG_KLOG, true, NULL); &st, true, LOG_KLOG, true, NULL, NULL, 0); } } } } Loading
logwrapper/include/logwrap/logwrap.h +21 −2 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ #define __LIBS_LOGWRAP_H #define __LIBS_LOGWRAP_H #include <stdbool.h> #include <stdbool.h> #include <stdint.h> __BEGIN_DECLS __BEGIN_DECLS Loading Loading @@ -53,6 +54,9 @@ __BEGIN_DECLS * the specified log until the child has exited. * the specified log until the child has exited. * file_path: if log_target has the LOG_FILE bit set, then this parameter * file_path: if log_target has the LOG_FILE bit set, then this parameter * must be set to the pathname of the file to log to. * must be set to the pathname of the file to log to. * opts: set to non-NULL if you want to use one or more of the * FORK_EXECVP_OPTION_* features. * opts_len: the length of the opts array. When opts is NULL, pass 0. * * * Return value: * Return value: * 0 when logwrap successfully run the child process and captured its status * 0 when logwrap successfully run the child process and captured its status Loading @@ -68,8 +72,22 @@ __BEGIN_DECLS #define LOG_KLOG 2 #define LOG_KLOG 2 #define LOG_FILE 4 #define LOG_FILE 4 /* Write data to child's stdin. */ #define FORK_EXECVP_OPTION_INPUT 0 struct AndroidForkExecvpOption { int opt_type; union { struct { const uint8_t* input; size_t input_len; } opt_input; }; }; int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int_quit, int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int_quit, int log_target, bool abbreviated, char *file_path); int log_target, bool abbreviated, char *file_path, const struct AndroidForkExecvpOption* opts, size_t opts_len); /* Similar to above, except abbreviated logging is not available, and if logwrap /* Similar to above, except abbreviated logging is not available, and if logwrap * is true, logging is to the Android system log, and if false, there is no * is true, logging is to the Android system log, and if false, there is no Loading @@ -79,7 +97,8 @@ static inline int android_fork_execvp(int argc, char* argv[], int *status, bool ignore_int_quit, bool logwrap) bool ignore_int_quit, bool logwrap) { { return android_fork_execvp_ext(argc, argv, status, ignore_int_quit, return android_fork_execvp_ext(argc, argv, status, ignore_int_quit, (logwrap ? LOG_ALOG : LOG_NONE), false, NULL); (logwrap ? LOG_ALOG : LOG_NONE), false, NULL, NULL, 0); } } __END_DECLS __END_DECLS Loading
logwrapper/logwrap.c +26 −2 Original line number Original line Diff line number Diff line Loading @@ -474,7 +474,8 @@ static void child(int argc, char* argv[]) { } } int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int_quit, int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int_quit, int log_target, bool abbreviated, char *file_path) { int log_target, bool abbreviated, char *file_path, const struct AndroidForkExecvpOption* opts, size_t opts_len) { pid_t pid; pid_t pid; int parent_ptty; int parent_ptty; int child_ptty; int child_ptty; Loading @@ -483,6 +484,7 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int sigset_t blockset; sigset_t blockset; sigset_t oldset; sigset_t oldset; int rc = 0; int rc = 0; size_t i; rc = pthread_mutex_lock(&fd_mutex); rc = pthread_mutex_lock(&fd_mutex); if (rc) { if (rc) { Loading Loading @@ -529,7 +531,13 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int pthread_sigmask(SIG_SETMASK, &oldset, NULL); pthread_sigmask(SIG_SETMASK, &oldset, NULL); close(parent_ptty); close(parent_ptty); // redirect stdout and stderr // redirect stdin, stdout and stderr for (i = 0; i < opts_len; ++i) { if (opts[i].opt_type == FORK_EXECVP_OPTION_INPUT) { dup2(child_ptty, 0); break; } } dup2(child_ptty, 1); dup2(child_ptty, 1); dup2(child_ptty, 2); dup2(child_ptty, 2); close(child_ptty); close(child_ptty); Loading @@ -546,6 +554,22 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int sigaction(SIGQUIT, &ignact, &quitact); sigaction(SIGQUIT, &ignact, &quitact); } } for (i = 0; i < opts_len; ++i) { if (opts[i].opt_type == FORK_EXECVP_OPTION_INPUT) { size_t left = opts[i].opt_input.input_len; const uint8_t* input = opts[i].opt_input.input; while (left > 0) { ssize_t res = TEMP_FAILURE_RETRY(write(parent_ptty, input, left)); if (res < 0) { break; } left -= res; input += res; } } } rc = parent(argv[0], parent_ptty, pid, status, log_target, rc = parent(argv[0], parent_ptty, pid, status, log_target, abbreviated, file_path); abbreviated, file_path); } } Loading
logwrapper/logwrapper.c +1 −1 Original line number Original line Diff line number Diff line Loading @@ -81,7 +81,7 @@ int main(int argc, char* argv[]) { } } rc = android_fork_execvp_ext(argc, &argv[0], &status, true, rc = android_fork_execvp_ext(argc, &argv[0], &status, true, log_target, abbreviated, NULL); log_target, abbreviated, NULL, NULL, 0); if (!rc) { if (!rc) { if (WIFEXITED(status)) if (WIFEXITED(status)) rc = WEXITSTATUS(status); rc = WEXITSTATUS(status); Loading