Skip to content

Commit

Permalink
run_command: encode deadly signal number in the return value
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Jul 6, 2009
1 parent 0ac77ec commit b99d5f4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,14 @@ static int wait_or_whine(pid_t pid, const char *argv0)
} else if (waiting != pid) {
error("waitpid is confused (%s)", argv0);
} else if (WIFSIGNALED(status)) {
error("%s died of signal", argv0);
code = WTERMSIG(status);
error("%s died of signal %d", argv0, code);
/*
* 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.
*/
code -= 128;
} else if (WIFEXITED(status)) {
code = WEXITSTATUS(status);
/*
Expand Down

0 comments on commit b99d5f4

Please sign in to comment.