summaryrefslogtreecommitdiff
path: root/run-command.c
diff options
context:
space:
mode:
Diffstat (limited to 'run-command.c')
-rw-r--r--run-command.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/run-command.c b/run-command.c
index 94ace50a25..1fb7fa5a8d 100644
--- a/run-command.c
+++ b/run-command.c
@@ -2,26 +2,26 @@
#include "run-command.h"
#include "exec_cmd.h"
-int run_command_v_opt(const char **argv, int flags)
+int run_command(struct child_process *cmd)
{
pid_t pid = fork();
if (pid < 0)
return -ERR_RUN_COMMAND_FORK;
if (!pid) {
- if (flags & RUN_COMMAND_NO_STDIN) {
+ if (cmd->no_stdin) {
int fd = open("/dev/null", O_RDWR);
dup2(fd, 0);
close(fd);
}
- if (flags & RUN_COMMAND_STDOUT_TO_STDERR)
+ if (cmd->stdout_to_stderr)
dup2(2, 1);
- if (flags & RUN_GIT_CMD) {
- execv_git_cmd(argv);
+ if (cmd->git_cmd) {
+ execv_git_cmd(cmd->argv);
} else {
- execvp(argv[0], (char *const*) argv);
+ execvp(cmd->argv[0], (char *const*) cmd->argv);
}
- die("exec %s failed.", argv[0]);
+ die("exec %s failed.", cmd->argv[0]);
}
for (;;) {
int status, code;
@@ -46,3 +46,14 @@ int run_command_v_opt(const char **argv, int flags)
return 0;
}
}
+
+int run_command_v_opt(const char **argv, int opt)
+{
+ struct child_process cmd;
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.argv = argv;
+ cmd.no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
+ cmd.git_cmd = opt & RUN_GIT_CMD ? 1 : 0;
+ cmd.stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
+ return run_command(&cmd);
+}