Skip to content

Commit

Permalink
Special case Process.exe for PID 0 & 4
Browse files Browse the repository at this point in the history
Solves issue #528 and #414
  • Loading branch information
mrjefftang committed Aug 21, 2014
1 parent 733b893 commit 37f56ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 1 addition & 7 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37f56ff

Please sign in to comment.