summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1358e7d)
raw | patch | inline | side by side (parent: 1358e7d)
author | Shawn O. Pearce <spearce@spearce.org> | |
Mon, 12 Mar 2007 18:37:28 +0000 (14:37 -0400) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 12 Mar 2007 23:31:35 +0000 (16:31 -0700) |
I started hacking on a change to add stdout redirection support to
the run_command family, but found I was using a lot of close calls
on two pipes in an array (such as for pipe). So I'm doing a tiny
bit of refactoring first to make the next set of changes clearer.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
the run_command family, but found I was using a lot of close calls
on two pipes in an array (such as for pipe). So I'm doing a tiny
bit of refactoring first to make the next set of changes clearer.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
run-command.c | patch | blob | history |
diff --git a/run-command.c b/run-command.c
index 03ff7bcac2a812bfa049255b499f25fdc14a0fd4..bef9775e0807200e07c9780c69e3e1bda0c6c874 100644 (file)
--- a/run-command.c
+++ b/run-command.c
#include "run-command.h"
#include "exec_cmd.h"
+static inline void close_pair(int fd[2])
+{
+ close(fd[0]);
+ close(fd[1]);
+}
+
int start_command(struct child_process *cmd)
{
int need_in = !cmd->no_stdin && cmd->in < 0;
cmd->pid = fork();
if (cmd->pid < 0) {
- if (need_in) {
- close(fdin[0]);
- close(fdin[1]);
- }
+ if (need_in)
+ close_pair(fdin);
return -ERR_RUN_COMMAND_FORK;
}
close(fd);
} else if (need_in) {
dup2(fdin[0], 0);
- close(fdin[0]);
- close(fdin[1]);
+ close_pair(fdin);
} else if (cmd->in) {
dup2(cmd->in, 0);
close(cmd->in);