Skip to content

Commit 246f0ed

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2b296c9 commit 246f0ed

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

git.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,16 @@ static void execv_dashed_external(const char **argv)
593593
trace_argv_printf(cmd.args.argv, "trace: exec:");
594594

595595
/*
596-
* if we fail because the command is not found, it is
597-
* OK to return. Otherwise, we just pass along the status code.
596+
* If we fail because the command is not found, it is
597+
* OK to return. Otherwise, we just pass along the status code,
598+
* or our usual generic code if we were not even able to exec
599+
* the program.
598600
*/
599601
status = run_command(&cmd);
600-
if (status >= 0 || errno != ENOENT)
602+
if (status >= 0)
601603
exit(status);
604+
else if (errno != ENOENT)
605+
exit(128);
602606
}
603607

604608
static int run_argv(int *argcp, const char ***argv)

0 commit comments

Comments
 (0)