Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special case Process.exe for PID 0 & 4 #529

Merged
merged 2 commits into from
Sep 15, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rephrase it like this:

if self.pid in (0, 4):
    raise AccessDenied(self.pid, self._name)

...then I will merge

return _convert_raw_path(cext.proc_exe(self.pid))

@wrap_exceptions
Expand Down