summaryrefslogtreecommitdiffstats
path: root/lib/system
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-08-13 13:03:53 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-08-19 13:27:59 +0800
commit51c6aaf7864eb65779d548ee2549caa357f71e2c (patch)
treec68d7b272c40a152c6ec65b2a1af70d6bbad2b13 /lib/system
parent823958fbbd17ab2c1b2a1779eb10351ca0a668c6 (diff)
downloadtalos-petitboot-51c6aaf7864eb65779d548ee2549caa357f71e2c.tar.gz
talos-petitboot-51c6aaf7864eb65779d548ee2549caa357f71e2c.zip
lib/process: replace pb_run_cmd
This change replaces the pb_run_cmd() function with proper usage of the process API. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/system.c79
1 files changed, 0 insertions, 79 deletions
diff --git a/lib/system/system.c b/lib/system/system.c
index ff4ae99..6e80b24 100644
--- a/lib/system/system.c
+++ b/lib/system/system.c
@@ -101,82 +101,3 @@ int pb_rmdir_recursive(const char *base, const char *dir)
return 0;
}
-
-/**
- * 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 wait, int dry_run)
-{
-#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;
-
- pb_log("%s: %s", __func__, (dry_run ? "(dry-run) " : ""));
-
- while (*p) {
- pb_log("%s ", *p);
- p++;
- }
- pb_log("\n");
- } else
- pb_log("%s: %s%s\n", __func__, (dry_run ? "(dry-run) " : ""),
- cmd_argv[0]);
-
- if (dry_run)
- return 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));
- return -1;
- }
-
- if (do_debug && WIFSIGNALED(status) && WTERMSIG(status) == SIGINT)
- pb_log("%s: signaled\n", __func__);
-
- if (!WIFEXITED(status)) {
- pb_log("%s: %s failed\n", __func__, cmd_argv[0]);
- return -1;
- }
-
- if (WEXITSTATUS(status))
- pb_log("%s: WEXITSTATUS %d\n", __func__, WEXITSTATUS(status));
-
- return WEXITSTATUS(status);
-}
OpenPOWER on IntegriCloud