]> git.cworth.org Git - apitrace/commitdiff
os_posix: Fix return value for os::execute()
authorCarl Worth <cworth@cworth.org>
Tue, 3 Apr 2012 22:58:50 +0000 (15:58 -0700)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 11 Apr 2012 13:57:55 +0000 (14:57 +0100)
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 <jose.r.fonseca@gmail.com>
common/os_posix.cpp

index ebd59a097076d05fe6b3eadf4c2ffae57a78547d..7d39d8ada5e0ffafc0f730bcdd3e913744f734d2 100644 (file)
@@ -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;
     }
 }