2 #include "run-command.h"
5 int run_command_v_opt(int argc, char **argv, int flags)
10 return -ERR_RUN_COMMAND_FORK;
12 if (flags & RUN_COMMAND_NO_STDIO) {
13 int fd = open("/dev/null", O_RDWR);
18 execvp(argv[0], (char *const*) argv);
19 die("exec %s failed.", argv[0]);
23 int retval = waitpid(pid, &status, 0);
28 error("waitpid failed (%s)", strerror(retval));
29 return -ERR_RUN_COMMAND_WAITPID;
32 return -ERR_RUN_COMMAND_WAITPID_WRONG_PID;
33 if (WIFSIGNALED(status))
34 return -ERR_RUN_COMMAND_WAITPID_SIGNAL;
36 if (!WIFEXITED(status))
37 return -ERR_RUN_COMMAND_WAITPID_NOEXIT;
38 code = WEXITSTATUS(status);
45 int run_command_v(int argc, char **argv)
47 return run_command_v_opt(argc, argv, 0);
50 int run_command(const char *cmd, ...)
53 char *argv[MAX_RUN_COMMAND_ARGS];
58 argv[0] = (char*) cmd;
60 while (argc < MAX_RUN_COMMAND_ARGS) {
61 arg = argv[argc++] = va_arg(param, char *);
66 if (MAX_RUN_COMMAND_ARGS <= argc)
67 return error("too many args to run %s", cmd);
68 return run_command_v_opt(argc, argv, 0);