git-commit-vandalism/Documentation/technical
Jeff King 709ca730f8 run-command: encode signal death as a positive integer
When a sub-command dies due to a signal, we encode the
signal number into the numeric exit status as "signal -
128". This is easy to identify (versus a regular positive
error code), and when cast to an unsigned integer (e.g., by
feeding it to exit), matches what a POSIX shell would return
when reporting a signal death in $? or through its own exit
code.

So we have a negative value inside the code, but once it
passes across an exit() barrier, it looks positive (and any
code we receive from a sub-shell will have the positive
form). E.g., death by SIGPIPE (signal 13) will look like
-115 to us in inside git, but will end up as 141 when we
call exit() with it. And a program killed by SIGPIPE but run
via the shell will come to us with an exit code of 141.

Unfortunately, this means that when the "use_shell" option
is set, we need to be on the lookout for _both_ forms. We
might or might not have actually invoked the shell (because
we optimize out some useless shell calls). If we didn't invoke
the shell, we will will see the sub-process's signal death
directly, and run-command converts it into a negative value.
But if we did invoke the shell, we will see the shell's
128+signal exit status. To be thorough, we would need to
check both, or cast the value to an unsigned char (after
checking that it is not -1, which is a magic error value).

Fortunately, most callsites do not care at all whether the
exit was from a code or from a signal; they merely check for
a non-zero status, and sometimes propagate the error via
exit(). But for the callers that do care, we can make life
slightly easier by just using the consistent positive form.

This actually fixes two minor bugs:

  1. In launch_editor, we check whether the editor died from
     SIGINT or SIGQUIT. But we checked only the negative
     form, meaning that we would fail to notice a signal
     death exit code which was propagated through the shell.

  2. In handle_alias, we assume that a negative return value
     from run_command means that errno tells us something
     interesting (like a fork failure, or ENOENT).
     Otherwise, we simply propagate the exit code. Negative
     signal death codes confuse us, and we print a useless
     "unable to run alias 'foo': Success" message. By
     encoding signal deaths using the positive form, the
     existing code just propagates it as it would a normal
     non-zero exit code.

The downside is that callers of run_command can no longer
differentiate between a signal received directly by the
sub-process, and one propagated. However, no caller
currently cares, and since we already optimize out some
calls to the shell under the hood, that distinction is not
something that should be relied upon by callers.

Fix the same logic in t/test-terminal.perl for consistency [jc:
raised by Jonathan in the discussion].

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-06 11:09:18 -08:00
..
.gitignore
api-allocation-growing.txt
api-argv-array.txt Merge branch 'fa/remote-svn' 2012-10-25 06:42:02 -04:00
api-builtin.txt add gitignore entry to description about how to write a builtin 2011-08-03 11:44:23 -07:00
api-config.txt docs: fix cross-directory linkgit references 2012-06-08 08:31:52 -07:00
api-credentials.txt add 'git credential' plumbing command 2012-06-25 11:55:51 -07:00
api-decorate.txt
api-diff.txt Documentation/technical/api-diff.txt: correct name of diff_unmerge() 2011-05-26 14:50:24 -07:00
api-directory-listing.txt
api-gitattributes.txt Rename git_checkattr() to git_check_attr() 2011-08-04 15:53:21 -07:00
api-grep.txt
api-hash.txt technical-docs: document hash API 2009-12-17 21:54:50 -08:00
api-history-graph.txt Documentation: undocument gc'd function graph_release() 2009-11-19 23:05:17 -08:00
api-in-core-index.txt
api-index-skel.txt
api-index.sh
api-lockfile.txt
api-merge.txt docs: fix cross-directory linkgit references 2012-06-08 08:31:52 -07:00
api-object-access.txt
api-parse-options.txt docs: stop using asciidoc no-inline-literal 2012-04-26 13:19:06 -07:00
api-quote.txt
api-ref-iteration.txt add technical documentation about ref iteration 2011-08-22 15:01:14 -07:00
api-remote.txt technical/api-remote: Describe new struct remote member pushurl 2009-06-09 23:46:47 -07:00
api-revision-walking.txt Teach revision walking machinery to walk multiple times sequencially 2012-03-30 08:57:49 -07:00
api-run-command.txt run-command: encode signal death as a positive integer 2013-01-06 11:09:18 -08:00
api-setup.txt
api-sha1-array.txt sha1-array.c: mark a private file-scope symbol as static 2012-09-15 22:58:21 -07:00
api-sigchain.txt Fix typos in the documentation 2011-01-04 11:23:42 -08:00
api-strbuf.txt strbuf: improve strbuf_get*line documentation 2012-02-23 13:52:11 -08:00
api-string-list.txt string_list API: document what "sorted" means 2012-09-18 11:41:06 -07:00
api-tree-walking.txt unpack_trees: group error messages by type 2010-08-11 10:36:06 -07:00
api-xdiff-interface.txt
index-format.txt index-v4: document the entry format 2012-04-27 16:03:31 -07:00
pack-format.txt
pack-heuristics.txt
pack-protocol.txt Doc: Improve shallow depth wording 2012-09-18 13:35:56 -07:00
protocol-capabilities.txt Documentation: Spelling fix in protocol-capabilities.txt 2010-07-09 17:36:28 -07:00
protocol-common.txt docs: stop using asciidoc no-inline-literal 2012-04-26 13:19:06 -07:00
racy-git.txt racy-git.txt: explain nsec problem in more detail 2009-10-09 14:56:32 -07:00
send-pack-pipeline.txt
shallow.txt
trivial-merge.txt