X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Fsystem%2Fsystem.c;h=1b506d2edaf6b5e84f9ea4211e0cac1b189f3d31;hp=380ddedadcd8a94de678e86e0af9da4a21fd7718;hb=604a1ccf072f9f33326fb6dc919c1b6233d40866;hpb=b3e1a66f23b7338d88e0668b8cf10ffe139a9a03 diff --git a/lib/system/system.c b/lib/system/system.c index 380dded..1b506d2 100644 --- a/lib/system/system.c +++ b/lib/system/system.c @@ -3,6 +3,7 @@ #include "config.h" #endif +#include #include #include #include @@ -16,9 +17,11 @@ #include "system.h" const struct pb_system_apps pb_system_apps = { + .prefix = PREFIX, .cp = "/bin/cp", .kexec = "/sbin/kexec", .mount = "/bin/mount", + .shutdown = "/sbin/shutdown", .sftp = "/usr/bin/sftp", .tftp = "/usr/bin/tftp", .umount = "/bin/umount", @@ -102,15 +105,15 @@ int pb_rmdir_recursive(const char *base, const char *dir) * @cmd_argv: An argument list array for execv. */ -int pb_run_cmd(const char *const *cmd_argv) +int pb_run_cmd(const char *const *cmd_argv, int wait) { - int status; - pid_t pid; #if defined(DEBUG) enum {do_debug = 1}; #else enum {do_debug = 0}; #endif + int status; + pid_t pid; if (do_debug) { const char *const *p = cmd_argv; @@ -125,17 +128,31 @@ int pb_run_cmd(const char *const *cmd_argv) pb_log("%s: %s\n", __func__, cmd_argv[0]); pid = fork(); + if (pid == -1) { pb_log("%s: fork failed: %s\n", __func__, strerror(errno)); return -1; } if (pid == 0) { + int log = fileno(pb_log_get_stream()); + + /* Redirect child output to log. */ + + status = dup2(log, STDOUT_FILENO); + assert(status != -1); + + status = dup2(log, STDERR_FILENO); + assert(status != -1); + execvp(cmd_argv[0], (char *const *)cmd_argv); pb_log("%s: exec failed: %s\n", __func__, strerror(errno)); exit(EXIT_FAILURE); } + if (!wait && !waitpid(pid, &status, WNOHANG)) + return 0; + if (waitpid(pid, &status, 0) == -1) { pb_log("%s: waitpid failed: %s\n", __func__, strerror(errno));