From 668637bc1c055e7597e83f7585fe3a988633a532 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 1 May 2023 19:48:12 +0000 Subject: [PATCH] Fix the WIFSTOPPED definition. Although this breaks job control in several shells (including mksh), this has been broken since the initial commit and no-one's noticed until now. Bug: https://github.com/android/ndk/issues/1878 Test: treehugger Change-Id: Id7c4805965c5e5847db99b57df1af13355adcc22 --- libc/include/bits/wait.h | 2 +- tests/sys_wait_test.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libc/include/bits/wait.h b/libc/include/bits/wait.h index a6a212904a..c7f1fb0978 100644 --- a/libc/include/bits/wait.h +++ b/libc/include/bits/wait.h @@ -53,7 +53,7 @@ #define WIFEXITED(__status) (WTERMSIG(__status) == 0) /** Returns true if the process was stopped by a signal. */ -#define WIFSTOPPED(__status) (WTERMSIG(__status) == 0x7f) +#define WIFSTOPPED(__status) (((__status) & 0xff) == 0x7f) /** Returns true if the process was terminated by a signal. */ #define WIFSIGNALED(__status) (WTERMSIG((__status)+1) >= 2) diff --git a/tests/sys_wait_test.cpp b/tests/sys_wait_test.cpp index c0069721d0..200fabe8a0 100644 --- a/tests/sys_wait_test.cpp +++ b/tests/sys_wait_test.cpp @@ -42,3 +42,22 @@ TEST(sys_wait, waitid) { ASSERT_EQ(66, si.si_status); ASSERT_EQ(CLD_EXITED, si.si_code); } + +// https://github.com/android/ndk/issues/1878 +TEST(sys_wait, macros) { +#if defined(__GLIBC__) + // glibc before 2016 requires an lvalue. +#else + ASSERT_FALSE(WIFEXITED(0x7f)); + ASSERT_TRUE(WIFSTOPPED(0x7f)); + ASSERT_FALSE(WIFCONTINUED(0x7f)); + + ASSERT_TRUE(WIFEXITED(0x80)); + ASSERT_FALSE(WIFSTOPPED(0x80)); + ASSERT_FALSE(WIFCONTINUED(0x80)); + + ASSERT_FALSE(WIFEXITED(0xffff)); + ASSERT_FALSE(WIFSTOPPED(0xffff)); + ASSERT_TRUE(WIFCONTINUED(0xffff)); +#endif +}