Skip to content

Commit

Permalink
giampaolo#1394 / windows / process exe(): convert errno 0 into ERROR_…
Browse files Browse the repository at this point in the history
…ACCESS_DENIED; errno 0 occurs when the Python process runs in 'Virtual Secure Mode'
  • Loading branch information
giampaolo committed Jan 25, 2019
1 parent c6b3e92 commit 6f4a622
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*

5.5.1
=====

XXXX-XX-XX

**Bug fixes**

- 1394_: [Windows] Process.exe() returns "[Error 0] The operation completed
successfully" when Python process runs in "Virtual Secure Mode".

5.5.0
=====

Expand Down
5 changes: 4 additions & 1 deletion psutil/_psutil_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
file = setmntent(mtab_path, "r");
Py_END_ALLOW_THREADS
if ((file == 0) || (file == NULL)) {
psutil_debug("setmntent() failed");
PyErr_SetFromErrnoWithFilename(PyExc_OSError, mtab_path);
goto error;
}
Expand Down Expand Up @@ -298,8 +299,10 @@ psutil_proc_cpu_affinity_get(PyObject *self, PyObject *args) {
while (1) {
setsize = CPU_ALLOC_SIZE(ncpus);
mask = CPU_ALLOC(ncpus);
if (mask == NULL)
if (mask == NULL) {
psutil_debug("CPU_ALLOC() failed");
return PyErr_NoMemory();
}
if (sched_getaffinity(pid, setsize, mask) == 0)
break;
CPU_FREE(mask);
Expand Down
6 changes: 5 additions & 1 deletion psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,11 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
if (NULL == hProcess)
return NULL;
if (GetProcessImageFileNameW(hProcess, exe, MAX_PATH) == 0) {
PyErr_SetFromWindowsErr(0);
// https://github.com/giampaolo/psutil/issues/1394
if (GetLastError() == 0)
PyErr_SetFromWindowsErr(ERROR_ACCESS_DENIED);
else
PyErr_SetFromWindowsErr(0);
CloseHandle(hProcess);
return NULL;
}
Expand Down
4 changes: 3 additions & 1 deletion psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ def exe(self):
# see https://github.com/giampaolo/psutil/issues/528
if self.pid in (0, 4):
raise AccessDenied(self.pid, self._name)
return py2_strencode(convert_dos_path(cext.proc_exe(self.pid)))
exe = cext.proc_exe(self.pid)
exe = convert_dos_path(exe)
return py2_strencode(exe)

@wrap_exceptions
def cmdline(self):
Expand Down

0 comments on commit 6f4a622

Please sign in to comment.