1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:57:35 +00:00

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
This commit is contained in:
SeekingBlues 2022-06-17 00:30:04 +08:00 committed by Andreas Kling
parent 8730e56e88
commit 4796a25bbd

View file

@ -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();
}