git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/6] Automatically close stderr pipes created by run_command
@ 2008-02-14  6:22 Shawn O. Pearce
  2008-02-14  8:00 ` Johannes Sixt
  0 siblings, 1 reply; 15+ messages in thread
From: Shawn O. Pearce @ 2008-02-14  6:22 UTC (permalink / raw)
  To: git

Like the out pipe and in pipe, we now automatically close the err
pipe if it was requested by the caller and it hasn't been closed
by the caller.  This simplifies anyone who wants to get a pipe to
the stderr stream for another process.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 run-command.c |    3 +++
 run-command.h |    1 +
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/run-command.c b/run-command.c
index 52f80be..7bf2cd7 100644
--- a/run-command.c
+++ b/run-command.c
@@ -51,6 +51,7 @@ int start_command(struct child_process *cmd)
 			return -ERR_RUN_COMMAND_PIPE;
 		}
 		cmd->err = fderr[0];
+		cmd->close_err = 1;
 	}
 
 	cmd->pid = fork();
@@ -161,6 +162,8 @@ int finish_command(struct child_process *cmd)
 		close(cmd->in);
 	if (cmd->close_out)
 		close(cmd->out);
+	if (cmd->close_err)
+		close(cmd->err);
 	return wait_or_whine(cmd->pid);
 }
 
diff --git a/run-command.h b/run-command.h
index 1fc781d..705cf2f 100644
--- a/run-command.h
+++ b/run-command.h
@@ -21,6 +21,7 @@ struct child_process {
 	const char *const *env;
 	unsigned close_in:1;
 	unsigned close_out:1;
+	unsigned close_err:1;
 	unsigned no_stdin:1;
 	unsigned no_stdout:1;
 	unsigned no_stderr:1;
-- 
1.5.4.1.1309.g833c2

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-02-22  1:18 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-14  6:22 [PATCH 2/6] Automatically close stderr pipes created by run_command Shawn O. Pearce
2008-02-14  8:00 ` Johannes Sixt
2008-02-15 17:11   ` Junio C Hamano
2008-02-15 19:45     ` Johannes Sixt
2008-02-15 22:14       ` Junio C Hamano
2008-02-16 17:36         ` [PATCH] start_command(), .in/.out/.err = -1: Callers must close the file descriptor Johannes Sixt
2008-02-16 17:36           ` [PATCH] start_command(), if .in/.out > 0, closes file descriptors, not the callers Johannes Sixt
2008-02-16 22:55             ` Junio C Hamano
2008-02-17  7:42               ` Shawn O. Pearce
2008-02-17  8:07                 ` Junio C Hamano
2008-02-17  8:20                   ` Shawn O. Pearce
2008-02-17  9:29               ` Johannes Sixt
2008-02-21 22:42                 ` [PATCH v2] " Johannes Sixt
2008-02-22  1:17                   ` Junio C Hamano
2008-02-16  8:25   ` [PATCH 2/6] Automatically close stderr pipes created by run_command Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).