diff --git a/libifupdown/execute.c b/libifupdown/execute.c index 563fa4c..04d29e6 100644 --- a/libifupdown/execute.c +++ b/libifupdown/execute.c @@ -29,7 +29,7 @@ #define SHELL "/bin/sh" bool -lif_execute_fmt(char *const envp[], const char *fmt, ...) +lif_execute_fmt(const struct lif_execute_opts *opts, char *const envp[], const char *fmt, ...) { char cmdbuf[4096]; va_list va; @@ -41,6 +41,12 @@ lif_execute_fmt(char *const envp[], const char *fmt, ...) pid_t child; char *argv[] = { SHELL, "-c", cmdbuf, NULL }; + if (opts->verbose) + puts(cmdbuf); + + if (opts->mock) + return true; + if (posix_spawn(&child, SHELL, NULL, NULL, argv, envp) != 0) { fprintf(stderr, "execute '%s': %s\n", cmdbuf, strerror(errno)); diff --git a/libifupdown/execute.h b/libifupdown/execute.h index 1a01248..b1f2eb5 100644 --- a/libifupdown/execute.h +++ b/libifupdown/execute.h @@ -19,6 +19,11 @@ #include #include -extern bool lif_execute_fmt(char *const envp[], const char *fmt, ...); +struct lif_execute_opts { + bool verbose; + bool mock; +}; + +extern bool lif_execute_fmt(const struct lif_execute_opts *opts, char *const envp[], const char *fmt, ...); #endif