From 4796a25bbd182d3c96379d219566322a1411a10d Mon Sep 17 00:00:00 2001 From: SeekingBlues Date: Fri, 17 Jun 2022 00:30:04 +0800 Subject: [PATCH] LibC: Make `waitpid`'s return value more POSIX-compliant * Always return 0 if `WNOHANG` is specified and no waitable child is found, even if `wstatus` is null. * Do not return 0 if the child is continued. Treat it the same way as all the other states. Refer to the RETURN VALUE section of the POSIX spec: https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html --- Userland/Libraries/LibC/sys/wait.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibC/sys/wait.cpp b/Userland/Libraries/LibC/sys/wait.cpp index 3affc55be8..41c896a24d 100644 --- a/Userland/Libraries/LibC/sys/wait.cpp +++ b/Userland/Libraries/LibC/sys/wait.cpp @@ -45,14 +45,13 @@ pid_t waitpid(pid_t waitee, int* wstatus, int options) if (rc < 0) return rc; - if (wstatus) { - if ((options & WNOHANG) && siginfo.si_pid == 0) { - // No child in a waitable state was found. All other fields - // in siginfo are undefined - *wstatus = 0; - return 0; - } + if ((options & WNOHANG) && siginfo.si_pid == 0) { + // No child in a waitable state was found. All other fields + // in siginfo are undefined + return 0; + } + if (wstatus) { switch (siginfo.si_code) { case CLD_EXITED: *wstatus = siginfo.si_status << 8; @@ -65,7 +64,7 @@ pid_t waitpid(pid_t waitee, int* wstatus, int options) break; case CLD_CONTINUED: *wstatus = 0xffff; - return 0; // return 0 if running + break; default: VERIFY_NOT_REACHED(); }