summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-19 21:41:34 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-19 21:41:34 +0200
commit5525254e4471707e6e7e1676fa9f743751709977 (patch)
tree8c258bbe4b9c1c12a71df6a2111555e40d9393ed
parent2e284cf73e143b1b8886c630fad6d497983ba681 (diff)
downloadpsutil-5525254e4471707e6e7e1676fa9f743751709977.tar.gz
check if pid is actually gone in psutil_handle_from_pid_waccess
-rw-r--r--psutil/arch/windows/process_info.c12
-rw-r--r--psutil/arch/windows/process_info.h4
2 files changed, 13 insertions, 3 deletions
diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c
index f514962f..1d47c432 100644
--- a/psutil/arch/windows/process_info.c
+++ b/psutil/arch/windows/process_info.c
@@ -179,8 +179,14 @@ psutil_handle_from_pid_waccess(DWORD pid, DWORD dwDesiredAccess) {
hProcess = OpenProcess(dwDesiredAccess, FALSE, pid);
if (hProcess == NULL) {
- if (GetLastError() == ERROR_INVALID_PARAMETER)
+ if (GetLastError() == ERROR_INVALID_PARAMETER) {
+ if (! psutil_assert_pid_not_exists(
+ pid, "psutil_handle_from_pid_waccess() -> OpenProcess "
+ "incorrectly assumed process is gone")) {
+ return NULL;
+ }
NoSuchProcess();
+ }
else
PyErr_SetFromWindowsErr(0);
return NULL;
@@ -272,8 +278,8 @@ psutil_assert_pid_exists(DWORD pid, char *err) {
PyErr_SetString(PyExc_AssertionError, err);
return 0;
}
- return 1;
}
+ return 1;
}
@@ -284,8 +290,8 @@ psutil_assert_pid_not_exists(DWORD pid, char *err) {
PyErr_SetString(PyExc_AssertionError, err);
return 0;
}
- return 1;
}
+ return 1;
}
diff --git a/psutil/arch/windows/process_info.h b/psutil/arch/windows/process_info.h
index a3b512e7..a2f70c2b 100644
--- a/psutil/arch/windows/process_info.h
+++ b/psutil/arch/windows/process_info.h
@@ -23,6 +23,10 @@ int psutil_pid_is_running(DWORD pid);
int psutil_get_proc_info(DWORD pid, PSYSTEM_PROCESS_INFORMATION *retProcess,
PVOID *retBuffer);
+int psutil_assert_pid_exists(DWORD pid, char *err);
+int psutil_assert_pid_not_exists(DWORD pid, char *err);
+
+
PyObject* psutil_get_cmdline(long pid);
PyObject* psutil_get_cwd(long pid);
PyObject* psutil_get_environ(long pid);