X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Fsystem%2Fsystem.c;h=d77159d5a7b882470648c740aa301b0314fd67c6;hp=7371445a876d0bdbd8e7ad2d7da49a5aa266e743;hb=52b9db95764fcdee9195113d7df225634a19c9f4;hpb=c763f15030565eef2e8b28fdf471ef3e7dd9b933 diff --git a/lib/system/system.c b/lib/system/system.c index 7371445..d77159d 100644 --- a/lib/system/system.c +++ b/lib/system/system.c @@ -17,6 +17,7 @@ #include "system.h" const struct pb_system_apps pb_system_apps = { + .prefix = PREFIX, .cp = "/bin/cp", .kexec = "/sbin/kexec", .mount = "/bin/mount", @@ -102,9 +103,11 @@ int pb_rmdir_recursive(const char *base, const char *dir) /** * pb_run_cmd - Run the supplied command. * @cmd_argv: An argument list array for execv. + * @wait: Wait for the child process to complete before returning. + * @dry_run: Don't actually fork and exec. */ -int pb_run_cmd(const char *const *cmd_argv) +int pb_run_cmd(const char *const *cmd_argv, int wait, int dry_run) { #if defined(DEBUG) enum {do_debug = 1}; @@ -117,14 +120,19 @@ int pb_run_cmd(const char *const *cmd_argv) if (do_debug) { const char *const *p = cmd_argv; - pb_log("%s: ", __func__); + pb_log("%s: %s", __func__, (dry_run ? "(dry-run) " : "")); + while (*p) { pb_log("%s ", *p); p++; } pb_log("\n"); } else - pb_log("%s: %s\n", __func__, cmd_argv[0]); + pb_log("%s: %s%s\n", __func__, (dry_run ? "(dry-run) " : ""), + cmd_argv[0]); + + if (dry_run) + return 0; pid = fork(); @@ -149,6 +157,9 @@ int pb_run_cmd(const char *const *cmd_argv) 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));