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:
@@ -1,6 +1,6 @@
|
|||||||
/// @file waitpid.c
|
/// @file waitpid.c
|
||||||
/// @brief
|
/// @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.
|
/// See LICENSE.md for details.
|
||||||
|
|
||||||
#include "sys/unistd.h"
|
#include "sys/unistd.h"
|
||||||
@@ -18,19 +18,17 @@ pid_t waitpid(pid_t pid, int *status, int options)
|
|||||||
int __status = 0;
|
int __status = 0;
|
||||||
do {
|
do {
|
||||||
__inline_syscall3(__res, waitpid, pid, &__status, options);
|
__inline_syscall3(__res, waitpid, pid, &__status, options);
|
||||||
if (__res < 0) {
|
if (__res != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (__status == EXIT_ZOMBIE) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (options && WNOHANG) {
|
if (options && WNOHANG) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
*status = __status;
|
*status = __status;
|
||||||
}
|
}
|
||||||
__syscall_return(pid_t, __res);
|
__syscall_return(pid_t, __res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user