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

[PATCH 5/7] run_command: encode deadly signal number in the return value

From
Johannes Sixt <j6t@kdbg.org>
Date
Jul 4, 2009, 19:26 UTC
Message-ID
<195a33e7de20a4b52df8cb8861998fbbbed0b311.1246734159.git.j6t@kdbg.org>
In-Reply-To
<ea2d8110ea70b8698bb3674ca4482db64053d841.1246734159.git.j6t@kdbg.org>

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>
---
 run-command.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/run-command.c b/run-command.c
index 4b3fda0..146a8ea 100644
--- a/run-command.c
+++ b/run-command.c
@@ -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);
 		/*
-- 
1.6.3.17.g1665f
Previous: Johannes SixtNext: Johannes Sixt
Message 6 of 12 in “rework run_command error reporting”
  1. 0/7 rework run_command error reportingJohannes Sixt, Jul 4, 2009
  2. 1/7 Truncate result of run_command that is used in exit() to lowest 8 bitsJohannes Sixt, Jul 4, 2009
  3. 2/7 MinGW: simplify waitpid() emulation macrosJohannes Sixt, Jul 4, 2009
  4. 3/7 run_command: return exit code as positive valueJohannes Sixt, Jul 4, 2009
  5. 4/7 run_command: report system call errors instead of returning error codesJohannes Sixt, Jul 4, 2009
  6. 5/7 run_command: encode deadly signal number in the return valueJohannes Sixt, Jul 4, 2009
  7. 6/7 run_command: report failure to execute the program, but optionally don'tJohannes Sixt, Jul 4, 2009
  8. 7/7 receive-pack: remove unnecessary run_status reportJohannes Sixt, Jul 4, 2009
  9. Johannes SixtJul 5, 2009
  10. Junio C HamanoJul 5, 2009
  11. Johannes SixtJul 6, 2009
  12. 1/7 MinGW: truncate exit()'s argument to lowest 8 bitsJohannes Sixt, Jul 5, 2009

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.