git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Fix start_command closing cmd->out/in regardless of cmd->close_out/in

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Nov 19, 2007, 07:39 UTC
Message-ID
<47413DB9.9030306@viscovery.net>
In-Reply-To
<1195407366-1610-1-git-send-email-pkufranky@gmail.com>
Ping Yin schrieb:
Show 26 quoted lines
> When 'FILE *fp' is assigned to child_process.out and then start_command or
> run_command is run, the standard output of the child process is expected to
> be outputed to fp. However, sometimes fp is not expected to be closed since
> further IO may be still performmed on fp.
> ---
>  run-command.c |    4 ----
>  1 files changed, 0 insertions(+), 4 deletions(-)
> 
> diff --git a/run-command.c b/run-command.c
> index 476d00c..4e5f58d 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -115,13 +115,9 @@ int start_command(struct child_process *cmd)
>  
>  	if (need_in)
>  		close(fdin[0]);
> -	else if (cmd->in)
> -		close(cmd->in);
>  
>  	if (need_out)
>  		close(fdout[1]);
> -	else if (cmd->out > 1)
> -		close(cmd->out);
>  
>  	if (need_err)
>  		close(fderr[1]);

This is dangerous! You have to audit all current callers whether they close cmd->in or cmd->out (if they don't need the fd anymore). Otherwise you risk to keep a writable pipe end open and then the reader hangs, waiting for input that will never arrive.

-- Hannes
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 4 in “Fix start_command closing cmd->out/in regardless of cmd->close_out/in”
  1. Fix start_command closing cmd->out/in regardless of cmd->close_out/inPing Yin, Nov 18, 2007
  2. Junio C HamanoNov 18, 2007
  3. Johannes SixtNov 19, 2007
  4. Junio C HamanoNov 19, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.