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

Re: [PATCH] transport-helper: check when helpers fail

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Oct 22, 2012, 06:35 UTC
Message-ID
<5084E931.3010809@viscovery.net>
In-Reply-To
<1350847158-14154-1-git-send-email-felipe.contreras@gmail.com>
Am 10/21/2012 21:19, schrieb Felipe Contreras:
Show 25 quoted lines
> diff --git a/run-command.c b/run-command.c
> index 1101ef7..2852e9d 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -559,6 +559,23 @@ int run_command(struct child_process *cmd)
>  	return finish_command(cmd);
>  }
>  
> +int check_command(struct child_process *cmd)
> +{
> +	int status;
> +	pid_t pid;
> +
> +	pid = waitpid(cmd->pid, &status, WNOHANG);
> +
> +	if (pid < 0)
> +		return -1;
> +	if (WIFSIGNALED(status))
> +		return WTERMSIG(status);
> +	if (WIFEXITED(status))
> +		return WEXITSTATUS(status);
> +
> +	return 0;
> +}
> +

In this form, the function is not suitable as a public run-command API: If the child did exit, it does not allow finish_command() to do its thing. The only thing the caller of this function can do is to die() if it returns non-zero. It doesn't report treat error cases in the same way as wait_or_whine().

I would expect the function to be usable in this way:
	start_command(&proc);
	loop {
		if (check_command(&proc))
			break;
	}
	finish_command(&proc);

but it would require a bit more work because it would have to cache the exit status in struct child_process.

BTW, you should check for return value 0 from waitpid() explicitly.

Another thought: In your use-case, isn't it so that it would be an error that the process exited for whatever reason? I.e., even if it exited with code 0 ("success"), it would be an error because it violated the protocol?

-- Hannes
Previous: Felipe ContrerasNext: Felipe Contreras
Message 4 of 9 in “transport-helper: check when helpers fail”
  1. transport-helper: check when helpers failFelipe Contreras, Oct 21, 2012
  2. Junio C HamanoOct 21, 2012
  3. Felipe ContrerasOct 21, 2012
  4. Johannes SixtOct 22, 2012
  5. Felipe ContrerasOct 22, 2012
  6. Johannes SixtOct 22, 2012
  7. Felipe ContrerasOct 22, 2012
  8. Felipe ContrerasOct 22, 2012
  9. Felipe ContrerasOct 22, 2012

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.