Merge "Fix the WIFSTOPPED definition." am: 721b93d7ec am: abeb9553ea am: 6be626aed6

Original change: https://android-review.googlesource.com/c/platform/bionic/+/2575250

Change-Id: I3544a624b43a54c98812dfbe539a881bc4579746
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Elliott Hughes 2023-05-02 16:46:20 +00:00 committed by Automerger Merge Worker
commit 260d821a84
2 changed files with 20 additions and 1 deletions

View file

@ -53,7 +53,7 @@
#define WIFEXITED(__status) (WTERMSIG(__status) == 0) #define WIFEXITED(__status) (WTERMSIG(__status) == 0)
/** Returns true if the process was stopped by a signal. */ /** 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. */ /** Returns true if the process was terminated by a signal. */
#define WIFSIGNALED(__status) (WTERMSIG((__status)+1) >= 2) #define WIFSIGNALED(__status) (WTERMSIG((__status)+1) >= 2)

View file

@ -42,3 +42,22 @@ TEST(sys_wait, waitid) {
ASSERT_EQ(66, si.si_status); ASSERT_EQ(66, si.si_status);
ASSERT_EQ(CLD_EXITED, si.si_code); 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
}