From a7ba350ff2c4cd68fd757822c277fe238d52031e Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 28 Aug 2007 03:31:30 +0000 Subject: [PATCH] Missed this one: Completed waitpid(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22089 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/sys/wait.c | 32 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/system/libroot/posix/sys/wait.c b/src/system/libroot/posix/sys/wait.c index c7ee68680b..3aa15d6349 100644 --- a/src/system/libroot/posix/sys/wait.c +++ b/src/system/libroot/posix/sys/wait.c @@ -28,22 +28,34 @@ waitpid(pid_t pid, int *_status, int options) status_t returnCode; int32 reason; - // TODO: there is no support for WUNTRACED and WCONTINUED yet! thread_id thread = _kern_wait_for_child(pid, options, &reason, &returnCode); if (thread >= B_OK && _status != NULL) { - int status = returnCode & 0xff; - // WEXITSTATUS() - // See kernel's wait_for_child() for how the return information is encoded: + // See kernel's wait_for_child() for how the return information is + // encoded: // reason = (signal << 16) | reason - // fill in signal for WIFSIGNALED() and WTERMSIG() - if (reason & THREAD_RETURN_INTERRUPTED) - status = (reason >> 8) & 0xff00; - - // TODO: fill in _status correctly for WIFSTOPPED(), WSTOPSIG(), WIFCORED(), - // and WIFCONTINUED() + int status; + switch (reason & 0xffff) { + case THREAD_RETURN_INTERRUPTED: + // fill in signal for WIFSIGNALED() and WTERMSIG() + status = (reason >> 8) & 0xff00; + break; + case THREAD_STOPPED: + // WIFSTOPPED() and WSTOPSIG() + status = reason & 0xff0000; + break; + case THREAD_CONTINUED: + // WIFCONTINUED() + status = 0x20000; + break; + case THREAD_RETURN_EXIT: + default: + // WEXITSTATUS() + status = returnCode & 0xff; + break; + } *_status = status; }