Skip to content

Commit 47e3de0

Browse files
j6tgitster
authored andcommitted
MinGW: truncate exit()'s argument to lowest 8 bits
For some reason, MinGW's bash cannot reliably detect failure of the child process if a negative value is passed to exit(). This fixes it by truncating the exit code in all calls of exit(). This issue was worked around in run_builtin() of git.c (2488df8 builtin run_command: do not exit with -1, 2007-11-15). This workaround is no longer necessary and is reverted. Suggested-by: Junio C Hamano <[email protected]> Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 606475f commit 47e3de0

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ static inline int fcntl(int fd, int cmd, long arg)
9292
errno = EINVAL;
9393
return -1;
9494
}
95+
/* bash cannot reliably detect negative return codes as failure */
96+
#define exit(code) exit((code) & 0xff)
9597

9698
/*
9799
* simple adaptors

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
245245

246246
status = p->fn(argc, argv, prefix);
247247
if (status)
248-
return status & 0xff;
248+
return status;
249249

250250
/* Somebody closed stdout? */
251251
if (fstat(fileno(stdout), &st))

0 commit comments

Comments
 (0)