2 #include "run-command.h"
5 int run_command(struct child_process *cmd)
10 return -ERR_RUN_COMMAND_FORK;
13 int fd = open("/dev/null", O_RDWR);
17 if (cmd->stdout_to_stderr)
20 execv_git_cmd(cmd->argv);
22 execvp(cmd->argv[0], (char *const*) cmd->argv);
24 die("exec %s failed.", cmd->argv[0]);
28 pid_t waiting = waitpid(pid, &status, 0);
33 error("waitpid failed (%s)", strerror(errno));
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_opt(const char **argv, int opt)
52 struct child_process cmd;
53 memset(&cmd, 0, sizeof(cmd));
55 cmd.no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
56 cmd.git_cmd = opt & RUN_GIT_CMD ? 1 : 0;
57 cmd.stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
58 return run_command(&cmd);