From 6f4d3b57f990a43b162d7bb0cc8effe08a178b4e Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 13 Jan 2024 14:12:23 +0100 Subject: [PATCH] libc: fix waitpid not detecting process termination Since 452aa40770592582830c90e1dab7f58325923e31 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. --- libc/src/unistd/waitpid.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libc/src/unistd/waitpid.c b/libc/src/unistd/waitpid.c index a02c2d9..b576f14 100644 --- a/libc/src/unistd/waitpid.c +++ b/libc/src/unistd/waitpid.c @@ -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,19 +18,17 @@ pid_t waitpid(pid_t pid, int *status, int options) int __status = 0; do { __inline_syscall3(__res, waitpid, pid, &__status, options); - if (__res < 0) { + if (__res != 0) { break; -} - if (__status == EXIT_ZOMBIE) { - break; -} + } if (options && WNOHANG) { break; -} + } } while (1); + if (status) { *status = __status; -} + } __syscall_return(pid_t, __res); }