From: Jeff King Date: Sat, 7 Jan 2017 01:17:48 +0000 (-0500) Subject: execv_dashed_external: stop exiting with negative code X-Git-Tag: v2.11.1~2^2~1 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/246f0edec0b789ccfeebcf7fef85417b7cb04425?ds=sidebyside;hp=2b296c93d49d65303a4ce291225c8755eeab1ff8 execv_dashed_external: stop exiting with negative code When we try to exec a git sub-command, we pass along the status code from run_command(). But that may return -1 if we ran into an error with pipe() or execve(). This tends to work (and end up as 255 due to twos-complement wraparound and truncation), but in general it's probably a good idea to avoid negative exit codes for portability. We can easily translate to the normal generic "128" code we get when syscalls cause us to die. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/git.c b/git.c index d0e04d5c97..bc2f2a7ec9 100644 --- a/git.c +++ b/git.c @@ -593,12 +593,16 @@ static void execv_dashed_external(const char **argv) trace_argv_printf(cmd.args.argv, "trace: exec:"); /* - * if we fail because the command is not found, it is - * OK to return. Otherwise, we just pass along the status code. + * If we fail because the command is not found, it is + * OK to return. Otherwise, we just pass along the status code, + * or our usual generic code if we were not even able to exec + * the program. */ status = run_command(&cmd); - if (status >= 0 || errno != ENOENT) + if (status >= 0) exit(status); + else if (errno != ENOENT) + exit(128); } static int run_argv(int *argcp, const char ***argv)