From df5489e0a4bcaa623622596aa58ee8234c031121 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sat, 23 Jul 2022 23:13:32 +0200 Subject: [PATCH] Allow for systems where wait status is signal/return The wait status value, which we also use internally, is read by a bunch of macros. Unfortunately because we want to *create* such a value, and some systems lack the "W_EXITCODE" macro to do that, we need to figure out how it's encoded. So we simply check a specific value, and assume the encoding from that. On Haiku the return status is in the lower byte, on other systems it's typically the upper byte. TODO: Test on musl (that's the other system without W_EXITCODE). Fixes #9067 --- src/proc.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/proc.h b/src/proc.h index 6ac42c753..1b6ed6e60 100644 --- a/src/proc.h +++ b/src/proc.h @@ -73,7 +73,12 @@ class proc_status_t { static constexpr int w_exitcode(int ret, int sig) { #ifdef W_EXITCODE return W_EXITCODE(ret, sig); +#elif WEXITSTATUS(0x007f) == 0x7f + // It's encoded signal and then status + // The return status is in the lower byte. + return ((sig) << 8 | (ret)); #else + // The status is encoded in the upper byte. return ((ret) << 8 | (sig)); #endif }