Re: [PATCHv3 05/13] run-command: factor out return value computation
From: Junio C Hamano <hidden>
Date: 2016-06-15 23:06:38
Stefan Beller [off-list ref] writes:
quoted hunk
We will need computing the return value in a later patch without the wait. Signed-off-by: Stefan Beller <redacted> --- run-command.c | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-)diff --git a/run-command.c b/run-command.c index 28e1d55..674e348 100644 --- a/run-command.c +++ b/run-command.c@@ -232,6 +232,35 @@ static inline void set_cloexec(int fd) fcntl(fd, F_SETFD, flags | FD_CLOEXEC); } +static int determine_return_value(int wait_status, + int *result, + int *error_code, + const char *argv0) +{ + if (WIFSIGNALED(wait_status)) { + *result = WTERMSIG(wait_status); + if (*result != SIGINT && *result != SIGQUIT) + error("%s died of signal %d", argv0, *result); + /* + * This return value is chosen so that code & 0xff + * mimics the exit code that a POSIX shell would report for + * a program that died from this signal. + */
Not a new problem but "from these signals", I think.
quoted hunk
@@ -244,29 +273,10 @@ static int wait_or_whine(pid_t pid, const char *argv0) if (waiting < 0) { failed_errno = errno; error("waitpid for %s failed: %s", argv0, strerror(errno)); -... } else { - error("waitpid is confused (%s)", argv0); + if (waiting != pid + || (determine_return_value(status, &code, &failed_errno, argv0) < 0))
Move "||" to the end of the previous line?
+ error("waitpid is confused (%s)", argv0);
}
clear_child_for_cleanup(pid);