Windows: Simplified `os::exists`.

os::exists determines if the process identified by the `pid` parameter
is present in the system. `OpenProcess` succeeds when the process object
exists and the caller has `PROCESS_QUERY_LIMITED_INFORMATION' right.

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


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

Branch: refs/heads/master
Commit: ec2a8a8f8ce2482101af21a2942fe70b5970eedd
Parents: 7d77556
Author: Daniel Pravat <[email protected]>
Authored: Mon May 30 18:00:15 2016 -0700
Committer: Joris Van Remoortere <[email protected]>
Committed: Mon May 30 18:00:46 2016 -0700

----------------------------------------------------------------------
 .../stout/include/stout/os/windows/exists.hpp     | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ec2a8a8f/3rdparty/stout/include/stout/os/windows/exists.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/exists.hpp 
b/3rdparty/stout/include/stout/os/windows/exists.hpp
index 423e4a8..6530869 100644
--- a/3rdparty/stout/include/stout/os/windows/exists.hpp
+++ b/3rdparty/stout/include/stout/os/windows/exists.hpp
@@ -59,24 +59,14 @@ inline bool exists(pid_t pid)
 {
   HANDLE handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
 
-  // NOTE: `GetExitCode` will gracefully deal with the case that `handle` is
-  // `NULL`.
-  DWORD exitCode = 0;
-  BOOL exitCodeExists = GetExitCodeProcess(handle, &exitCode);
-
-  // `CloseHandle`, on the other hand, will throw an exception in the
-  // VS debugger if you pass it a broken handle. (cf. "Return value"
-  // section of the documentation[1].)
-  //
-  // [1] 
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx
+  bool has_handle = false;
+
   if (handle != NULL) {
+    has_handle = true;
     CloseHandle(handle);
   }
 
-  // NOTE: Windows quirk, the exit code returned by the process can
-  // be the same number as `STILL_ACTIVE`, in which case this
-  // function will mis-report that the process still exists.
-  return exitCodeExists && (exitCode == STILL_ACTIVE);
+  return has_handle;
 }
 
 

Reply via email to