From 3cbd4a09f7cf3e35086c95cb3e41f0e29b154519 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 3 Nov 2008 16:35:09 +0000 Subject: [PATCH] system() is supposed to return a waitpid() style exit status value. wait_for_thread() doesn't provide that; use waitpid() instead. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28479 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/unistd/system.cpp | 36 ++++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/system/libroot/posix/unistd/system.cpp b/src/system/libroot/posix/unistd/system.cpp index bf156e7e43..c3285ad87e 100644 --- a/src/system/libroot/posix/unistd/system.cpp +++ b/src/system/libroot/posix/unistd/system.cpp @@ -1,14 +1,14 @@ -/* -** Copyright 2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ - +/* + * Copyright 2004-2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ #include -#include -#include #include +#include +#include +#include extern "C" int @@ -26,15 +26,17 @@ system(const char *command) return -1; } - status_t returnValue; - status_t error; - do { - error = wait_for_thread(thread, &returnValue); - } while (error == B_INTERRUPTED); - - if (error != B_OK) { - errno = error; - return -1; + resume_thread(thread); + + int exitStatus; + pid_t result; + while ((result = waitpid(thread, &exitStatus, 0)) < 0 + && errno == B_INTERRUPTED) { + // waitpid() was interrupted by a signal, retry... } - return returnValue; + + if (result < 0) + return -1; + + return exitStatus; }