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
This commit is contained in:
Fabian Boehm 2022-07-23 23:13:32 +02:00
parent dd815eef38
commit df5489e0a4

View File

@ -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
}