killdaemons: fix WaitForSingleObject() error handling logic on Windows
authorMatt Harbison <matt_harbison@yahoo.com>
Thu, 15 Jun 2017 21:59:42 -0400
changeset 32876 ed1f376090cd
parent 32875 d644e859d9da
child 32877 a05f3675c46a
killdaemons: fix WaitForSingleObject() error handling logic on Windows The error return is not 0 for this method, so _check() was doing nothing when an error occurred. This forces the error path, much like the check for OpenProcess(). The only unhandled return is now WAIT_ABANDONED, but I don't see how that could happen in this case.
tests/killdaemons.py
--- a/tests/killdaemons.py	Tue Jun 06 20:18:06 2017 -0400
+++ b/tests/killdaemons.py	Thu Jun 15 21:59:42 2017 -0400
@@ -44,6 +44,7 @@
         SYNCHRONIZE = 0x00100000
         WAIT_OBJECT_0 = 0
         WAIT_TIMEOUT = 258
+        WAIT_FAILED = _DWORD(0xFFFFFFFF).value
         handle = ctypes.windll.kernel32.OpenProcess(
                 PROCESS_TERMINATE|SYNCHRONIZE|PROCESS_QUERY_INFORMATION,
                 False, pid)
@@ -56,8 +57,8 @@
                 pass # terminated, but process handle still available
             elif r == WAIT_TIMEOUT:
                 _check(ctypes.windll.kernel32.TerminateProcess(handle, -1))
-            else:
-                _check(r)
+            elif r == WAIT_FAILED:
+                _check(0)  # err stored in GetLastError()
 
             # TODO?: forcefully kill when timeout
             #        and ?shorter waiting time? when tryhard==True
@@ -67,8 +68,8 @@
                 pass # process is terminated
             elif r == WAIT_TIMEOUT:
                 logfn('# Daemon process %d is stuck')
-            else:
-                _check(r) # any error
+            elif r == WAIT_FAILED:
+                _check(0)  # err stored in GetLastError()
         except: #re-raises
             ctypes.windll.kernel32.CloseHandle(handle) # no _check, keep error
             raise