Am 10/21/2012 21:19, schrieb Felipe Contreras:
> 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
I would expect the function to be usable in this way:
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?
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html