diff options
author | SeekingBlues <seekingblues@gmail.com> | 2022-06-17 00:30:04 +0800 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-06-17 10:59:26 +0200 |
commit | 4796a25bbd182d3c96379d219566322a1411a10d (patch) | |
tree | 551c6e64c9506696bcabf5916879923db64bd758 /Userland/Libraries/LibC | |
parent | 8730e56e882f5f4082b0e24ce3948ed035a2046a (diff) | |
download | serenity-4796a25bbd182d3c96379d219566322a1411a10d.zip |
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
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r-- | Userland/Libraries/LibC/sys/wait.cpp | 15 |
1 files 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(); } |