From 4644dc65e83c56ba0bb577f57cd20e7419f3ade4 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 3 Apr 2012 15:58:50 -0700 Subject: [PATCH] os_posix: Fix return value for os::execute() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Previously, this was returning the status value from waitpid directly. That is incorrect as the actual exit status from the executed program is likely to be in high-order bits of that status value. Instead, use the WEXITSTATUS macro to return the actual exit status value. Signed-off-by: José Fonseca --- common/os_posix.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/os_posix.cpp b/common/os_posix.cpp index ebd59a0..7d39d8a 100644 --- a/common/os_posix.cpp +++ b/common/os_posix.cpp @@ -143,8 +143,17 @@ int execute(char * const * args) return -1; } int status = -1; + int ret; waitpid(pid, &status, 0); - return status; + if (WIFEXITED(status)) { + ret = WEXITSTATUS(status); + } else if (WIFSIGNALED(status)) { + // match shell return code + ret = WTERMSIG(status) + 128; + } else { + ret = 128; + } + return ret; } } -- 2.43.0