summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGeoff Levand <geoff@infradead.org>2012-03-30 16:58:32 -0700
committerGeoff Levand <geoff@infradead.org>2012-03-30 18:08:57 -0700
commit52b9db95764fcdee9195113d7df225634a19c9f4 (patch)
treec1d649ca1316a816430728ce097acb1806f2fad9 /lib
parent45e253470f2cd7c6dfc38e7f533c62c454039873 (diff)
downloadtalos-petitboot-52b9db95764fcdee9195113d7df225634a19c9f4.tar.gz
talos-petitboot-52b9db95764fcdee9195113d7df225634a19c9f4.zip
Cleanup --dry-run option code
Signed-off-by: Geoff Levand <geoff@infradead.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/system/system.c13
-rw-r--r--lib/system/system.h2
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/system/system.c b/lib/system/system.c
index 1b506d2..d77159d 100644
--- a/lib/system/system.c
+++ b/lib/system/system.c
@@ -103,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 wait)
+int pb_run_cmd(const char *const *cmd_argv, int wait, int dry_run)
{
#if defined(DEBUG)
enum {do_debug = 1};
@@ -118,14 +120,19 @@ int pb_run_cmd(const char *const *cmd_argv, int wait)
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();
diff --git a/lib/system/system.h b/lib/system/system.h
index d39280d..f8f18a3 100644
--- a/lib/system/system.h
+++ b/lib/system/system.h
@@ -15,7 +15,7 @@ struct pb_system_apps {
extern const struct pb_system_apps pb_system_apps;
-int pb_run_cmd(const char *const *cmd_argv, int wait);
+int pb_run_cmd(const char *const *cmd_argv, int wait, int dry_run);
int pb_mkdir_recursive(const char *dir);
int pb_rmdir_recursive(const char *base, const char *dir);
OpenPOWER on IntegriCloud