Windows: Fixed `WIFEXITED` and `WIFSIGNALED` stubs.

The `WIFEXITED` and `WIFSIGNALED` macros were incorrectly checking if
the exit code was not -1 to determine if the process exited or was
signaled. However, -1 is a valid return code on Windows, so when logic
like `CHECK(WIFEXITED(status)|| WIFSIGNALED(status))` was used, it
would end up aborting the process accidentally.

For `WIFEXITED`, we simply return `true` because all error codes on
Windows indicate the process exited (if the process instead failed to
spawn, then `os::spawn()` would return `None()` instead of an exit
code).

For `WIFIGNALED`, we simply return `false` for similar reasons. We
assume the process did not exit due to a signal, as that is not an
expected scenario on Windows.

Review: https://reviews.apache.org/r/65840/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ca357e95
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ca357e95
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ca357e95

Branch: refs/heads/master
Commit: ca357e95f62604329dcb57076af10a86e8c25a41
Parents: 5ca0f58
Author: Akash Gupta <akash-gu...@hotmail.com>
Authored: Tue Mar 6 13:11:19 2018 -0800
Committer: Andrew Schwartzmeyer <and...@schwartzmeyer.com>
Committed: Tue Mar 6 13:41:49 2018 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows.hpp | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ca357e95/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows.hpp 
b/3rdparty/stout/include/stout/windows.hpp
index 8f7817a..1bfcdf4 100644
--- a/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/stout/include/stout/windows.hpp
@@ -364,10 +364,13 @@ inline const char* strsignal(int signum)
 
 #define SIGPIPE 100
 
-// `os::system` returns -1 if the processor cannot be started
-// therefore any return value indicates the process has been started
+// On Windows, the exit code, unlike Linux, is simply a 32 bit unsigned integer
+// with no special encoding. Since the `status` value from `waitpid` returns a
+// 32 bit integer, we can't use it to determine if the process exited normally,
+// because all the possibilities could be valid exit codes. So, we assume that
+// if we get an exit code, the process exited normally.
 #ifndef WIFEXITED
-#define WIFEXITED(x) ((x) != -1)
+#define WIFEXITED(x) true
 #endif // WIFEXITED
 
 // Returns the exit status of the child.
@@ -376,8 +379,12 @@ inline const char* strsignal(int signum)
 #define WEXITSTATUS(x) static_cast<DWORD>(x)
 #endif // WEXITSTATUS
 
+// A signaled Windows process always exits with status code 3, but it's
+// impossible to distinguish that from a process that exits normally with
+// status code 3. Since signals aren't really used on Windows, we will
+// assume that the process is not signaled.
 #ifndef WIFSIGNALED
-#define WIFSIGNALED(x) ((x) != -1)
+#define WIFSIGNALED(x) false
 #endif // WIFSIGNALED
 
 // Specifies that `::waitpid` should return immediately rather than

Reply via email to