2 #include "run-command.h"
6 int run_command_v_opt(int argc, const char **argv, int flags)
11 return -ERR_RUN_COMMAND_FORK;
13 if (flags & RUN_COMMAND_NO_STDIO) {
14 int fd = open("/dev/null", O_RDWR);
19 if (flags & RUN_GIT_CMD) {
22 execvp(argv[0], (char *const*) argv);
24 die("exec %s failed.", argv[0]);
28 int retval = waitpid(pid, &status, 0);
33 error("waitpid failed (%s)", strerror(retval));
34 return -ERR_RUN_COMMAND_WAITPID;
37 return -ERR_RUN_COMMAND_WAITPID_WRONG_PID;
38 if (WIFSIGNALED(status))
39 return -ERR_RUN_COMMAND_WAITPID_SIGNAL;
41 if (!WIFEXITED(status))
42 return -ERR_RUN_COMMAND_WAITPID_NOEXIT;
43 code = WEXITSTATUS(status);
50 int run_command_v(int argc, const char **argv)
52 return run_command_v_opt(argc, argv, 0);
55 int run_command(const char *cmd, ...)
58 const char *argv[MAX_RUN_COMMAND_ARGS];
63 argv[0] = (char*) cmd;
65 while (argc < MAX_RUN_COMMAND_ARGS) {
66 arg = argv[argc++] = va_arg(param, char *);
71 if (MAX_RUN_COMMAND_ARGS <= argc)
72 return error("too many args to run %s", cmd);
73 return run_command_v_opt(argc, argv, 0);