From 4006b38ffa32b547b81f6344c412d64fe1f220ff Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Thu, 23 Jul 2020 08:22:26 -0600 Subject: [PATCH] execute: add lif_execute_opts structure --- libifupdown/execute.c | 8 +++++++- libifupdown/execute.h | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) 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