4 // Stolen from the test routines from the apfs project.
15 #include "test_utils.h"
18 int __attribute__((sentinel
)) systemx(const char *prog
, ...)
24 const char **parg
= args
;
26 *parg
++ = basename((char *)prog
);
30 bool quiet
= false, quiet_stderr
= false;
32 while ((*parg
= va_arg(ap
, char *))) {
33 if (*parg
== SYSTEMX_QUIET
) {
35 } else if (*parg
== SYSTEMX_QUIET_STDERR
)
43 posix_spawn_file_actions_t facts
, *pfacts
= NULL
;
45 if (quiet
|| quiet_stderr
) {
46 posix_spawn_file_actions_init(&facts
);
48 posix_spawn_file_actions_addopen(&facts
, STDOUT_FILENO
, "/dev/null", O_APPEND
, 0);
50 posix_spawn_file_actions_addopen(&facts
, STDERR_FILENO
, "/dev/null", O_APPEND
, 0);
55 assert_no_err(errno
= posix_spawn(&pid
, prog
, pfacts
, NULL
,
56 (char * const *)args
, NULL
));
59 posix_spawn_file_actions_destroy(pfacts
);
62 assert(ignore_eintr(waitpid(pid
, &status
, 0), -1) == pid
);
64 if (WIFEXITED(status
))
65 return WEXITSTATUS(status
);