@matheusbsbs / matheus-bagliano / commits / b99d5f40d6
Fork 0

run_command: encode deadly signal number in the return value

We now write the signal number in the error message if the program terminated by a signal. The negative return value is constructed such that after truncation to 8 bits it looks like a POSIX shell's $?: $ echo 0000 | { git upload-pack .; echo $? >&2; } | : error: git-upload-pack died of signal 13 141 Previously, the exit code was 255 instead of 141. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Jul 4, 2009 at 21:26 UTC b99d5f40d6a5cba7d7cd7599063b3cd78aa4d219
1 file changed +8 -1
run-command.c
+8 -1
@@ -248,7 +248,14 @@ static int wait_or_whine(pid_t pid, const char *argv0)
248 } else if (waiting != pid) {
249 error("waitpid is confused (%s)", argv0);
250 } else if (WIFSIGNALED(status)) {
251 - error("%s died of signal", argv0);
251 + code = WTERMSIG(status);
252 + error("%s died of signal %d", argv0, code);
253 + /*
254 + * This return value is chosen so that code & 0xff
255 + * mimics the exit code that a POSIX shell would report for
256 + * a program that died from this signal.
257 + */
258 + code -= 128;
259 } else if (WIFEXITED(status)) {
260 code = WEXITSTATUS(status);
261 /*