execute: add lif_execute_opts structure
This commit is contained in:
parent
a567d5d0f5
commit
4006b38ffa
2 changed files with 13 additions and 2 deletions
|
@ -29,7 +29,7 @@
|
||||||
#define SHELL "/bin/sh"
|
#define SHELL "/bin/sh"
|
||||||
|
|
||||||
bool
|
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];
|
char cmdbuf[4096];
|
||||||
va_list va;
|
va_list va;
|
||||||
|
@ -41,6 +41,12 @@ lif_execute_fmt(char *const envp[], const char *fmt, ...)
|
||||||
pid_t child;
|
pid_t child;
|
||||||
char *argv[] = { SHELL, "-c", cmdbuf, NULL };
|
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)
|
if (posix_spawn(&child, SHELL, NULL, NULL, argv, envp) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "execute '%s': %s\n", cmdbuf, strerror(errno));
|
fprintf(stderr, "execute '%s': %s\n", cmdbuf, strerror(errno));
|
||||||
|
|
|
@ -19,6 +19,11 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
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
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue