From 37f56ffa74b560361f42d73c2d18306dbdfdcd84 Mon Sep 17 00:00:00 2001 From: Jeff Tang Date: Thu, 21 Aug 2014 11:26:57 -0400 Subject: [PATCH 1/2] Special case Process.exe for PID 0 & 4 Solves issue #528 and #414 --- psutil/_psutil_windows.c | 8 +------- psutil/_pswindows.py | 7 +++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 7ad8c9589..066a919af 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -573,13 +573,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) { } if (GetProcessImageFileNameW(hProcess, &exe, MAX_PATH) == 0) { CloseHandle(hProcess); - if (GetLastError() == ERROR_INVALID_PARAMETER) { - // see https://github.com/giampaolo/psutil/issues/414 - AccessDenied(); - } - else { - PyErr_SetFromWindowsErr(0); - } + PyErr_SetFromWindowsErr(0); return NULL; } CloseHandle(hProcess); diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 1a786f103..223943511 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -245,6 +245,13 @@ def exe(self): # Note: os.path.exists(path) may return False even if the file # is there, see: # http://stackoverflow.com/questions/3112546/os-path-exists-lies + + # see https://github.com/giampaolo/psutil/issues/414 + # see https://github.com/giampaolo/psutil/issues/528 + if self.pid == 0: + raise AccessDenied(self.pid, self._name) + elif self.pid == 4: + raise AccessDenied(self.pid, self._name) return _convert_raw_path(cext.proc_exe(self.pid)) @wrap_exceptions From ae332ec0f7d6b5df23b25fa88577eb5dd341c473 Mon Sep 17 00:00:00 2001 From: Jeff Tang Date: Mon, 15 Sep 2014 11:37:18 -0400 Subject: [PATCH 2/2] Cleaned up syntax --- psutil/_pswindows.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 223943511..b540bdac2 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -248,9 +248,7 @@ def exe(self): # see https://github.com/giampaolo/psutil/issues/414 # see https://github.com/giampaolo/psutil/issues/528 - if self.pid == 0: - raise AccessDenied(self.pid, self._name) - elif self.pid == 4: + if self.pid in (0, 4): raise AccessDenied(self.pid, self._name) return _convert_raw_path(cext.proc_exe(self.pid))