summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin Adler <kadler@us.ibm.com>2020-10-31 05:35:44 (GMT)
committerKevin Adler <kadler@us.ibm.com>2020-10-31 06:02:37 (GMT)
commit7ea6c537d2968effb024634a6367a1a1b4cafeb4 (patch)
treed4215b7068389d83e05f074775ca293e07d734a5 /src
parentd45ff8ebf88ef4add46a80ccdfc2d97a8b4b091b (diff)
downloadNinja-7ea6c537d2968effb024634a6367a1a1b4cafeb4.zip
Ninja-7ea6c537d2968effb024634a6367a1a1b4cafeb4.tar.gz
Ninja-7ea6c537d2968effb024634a6367a1a1b4cafeb4.tar.bz2
Handle process signalling correctly on AIX
POSIX shells set the exit code to 128 + the signal number, which coincidentally matches the layout used by the WIFSIGNALLED/WTERMSIG macros on most Unix-like systems, but not on AIX. Instead, AIX stores the signal value in the bottom 8 bits and also bits 16-23. The only time ninja currently handles signals correctly is when the shell used to call the program dies via signal. To handle both scenarios, we detect the shell exit code format and convert it to the format that the WIFSIGNALED/WTERMSIG macros expect. Fixes #1623
Diffstat (limited to 'src')
-rw-r--r--src/subprocess-posix.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc
index 0c5f556..8e78540 100644
--- a/src/subprocess-posix.cc
+++ b/src/subprocess-posix.cc
@@ -154,6 +154,16 @@ ExitStatus Subprocess::Finish() {
Fatal("waitpid(%d): %s", pid_, strerror(errno));
pid_ = -1;
+#ifdef _AIX
+ if (WIFEXITED(status) && WEXITSTATUS(status) & 0x80) {
+ // Map the shell's exit code used for signal failure (128 + signal) to the
+ // status code expected by AIX WIFSIGNALED and WTERMSIG macros which, unlike
+ // other systems, uses a different bit layout.
+ int signal = WEXITSTATUS(status) & 0x7f;
+ status = (signal << 16) | signal;
+ }
+#endif
+
if (WIFEXITED(status)) {
int exit = WEXITSTATUS(status);
if (exit == 0)