{"thread":{"id":"11794","subject":"[PATCH 3/7] Automatically close stderr pipes created by run_command","startedAt":"2008-01-30T06:22:02Z","lastAt":"2008-01-30T06:22:02Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"66890","messageId":"20080130062202.GC15838@spearce.org","threadId":"11794","inReplyTo":null,"subject":"[PATCH 3/7] Automatically close stderr pipes created by run_command","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-01-30T06:22:02Z","receivedAt":"2008-01-30T06:22:02Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Like the out pipe and in pipe, we now automatically close the err\npipe if it was requested by the caller and it hasn't been closed\nby the caller.  This simplifies anyone who wants to get a pipe to\nthe stderr stream for another process.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n run-command.c |    3 +++\n run-command.h |    1 +\n 2 files changed, 4 insertions(+), 0 deletions(-)\n\ndiff --git a/run-command.c b/run-command.c\nindex 52f80be..7bf2cd7 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -51,6 +51,7 @@ int start_command(struct child_process *cmd)\n \t\t\treturn -ERR_RUN_COMMAND_PIPE;\n \t\t}\n \t\tcmd->err = fderr[0];\n+\t\tcmd->close_err = 1;\n \t}\n \n \tcmd->pid = fork();\n@@ -161,6 +162,8 @@ int finish_command(struct child_process *cmd)\n \t\tclose(cmd->in);\n \tif (cmd->close_out)\n \t\tclose(cmd->out);\n+\tif (cmd->close_err)\n+\t\tclose(cmd->err);\n \treturn wait_or_whine(cmd->pid);\n }\n \ndiff --git a/run-command.h b/run-command.h\nindex 1fc781d..705cf2f 100644\n--- a/run-command.h\n+++ b/run-command.h\n@@ -21,6 +21,7 @@ struct child_process {\n \tconst char *const *env;\n \tunsigned close_in:1;\n \tunsigned close_out:1;\n+\tunsigned close_err:1;\n \tunsigned no_stdin:1;\n \tunsigned no_stdout:1;\n \tunsigned no_stderr:1;\n-- \n1.5.4.rc5.1126.g6ba14\n"}]}