From 7ea6c537d2968effb024634a6367a1a1b4cafeb4 Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Sat, 31 Oct 2020 00:35:44 -0500 Subject: 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 --- src/subprocess-posix.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) -- cgit v0.12