libc: fix waitpid not detecting process termination

Since 452aa40770 and the change to
properly return processes exit codes in the status argument, the
status will never be EXIT_ZOMBIE(16) except a process was terminated by
signal(16).

Return from waitpid if either an error occurred (__res < 0) or
we got the status of a child process (__res == cpid).

Additionally fix the weird alignment of the closing braces.
This commit is contained in:
Florian Fischer
2024-01-13 14:12:23 +01:00
parent dd39e93194
commit 6f4d3b57f9
+3 -5
View File
@@ -1,6 +1,6 @@
/// @file waitpid.c
/// @brief
/// @copyright (c) 2014-2023 This file is distributed under the MIT License.
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "sys/unistd.h"
@@ -18,16 +18,14 @@ pid_t waitpid(pid_t pid, int *status, int options)
int __status = 0;
do {
__inline_syscall3(__res, waitpid, pid, &__status, options);
if (__res < 0) {
break;
}
if (__status == EXIT_ZOMBIE) {
if (__res != 0) {
break;
}
if (options && WNOHANG) {
break;
}
} while (1);
if (status) {
*status = __status;
}