From 6f4a6228998df48ee09413377785d13d2eec7998 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Fri, 25 Jan 2019 16:36:17 +0100 Subject: [PATCH] #1394 / windows / process exe(): convert errno 0 into ERROR_ACCESS_DENIED; errno 0 occurs when the Python process runs in 'Virtual Secure Mode' --- HISTORY.rst | 10 ++++++++++ psutil/_psutil_linux.c | 5 ++++- psutil/_psutil_windows.c | 6 +++++- psutil/_pswindows.py | 4 +++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 44afa960f..095c90623 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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 ===== diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index bd27b5f9c..5b7a56ad9 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -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; } @@ -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); diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index ce44258a3..4251e0c71 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -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; } diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index bb5882422..664d5b6b1 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -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):