diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-12-14 00:46:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-14 00:46:18 +0100 |
commit | 6ea12c3c0a93b1370a1db2670cda60eadbf618dd (patch) | |
tree | d539884bba44640a1abc7d852a05467abdd12636 | |
parent | 70b273265d0329868eac37f199261d7ef8fc1ad3 (diff) | |
download | psutil-6ea12c3c0a93b1370a1db2670cda60eadbf618dd.tar.gz |
[macOS] EIO error occurring on cmdline() and environ (#1886)
See: https://github.com/nicolargo/glances/issues/1769
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rw-r--r-- | HISTORY.rst | 2 | ||||
-rw-r--r-- | psutil/arch/osx/process_info.c | 22 |
2 files changed, 17 insertions, 7 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index 99e85a5b..ea283782 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -20,6 +20,8 @@ XXXX-XX-XX - 1866_: [Windows] process exe(), cmdline(), environ() may raise "invalid access to memory location" on Python 3.9. - 1874_: [Solaris] wrong swap output given when encrypted column is present +- 1886_: [macOS] EIO error may be raised on cmdline() and environment(). Now + it gets translated into AccessDenied. 5.7.3 ===== diff --git a/psutil/arch/osx/process_info.c b/psutil/arch/osx/process_info.c index 1dca7364..3732f91d 100644 --- a/psutil/arch/osx/process_info.c +++ b/psutil/arch/osx/process_info.c @@ -124,16 +124,24 @@ psutil_sysctl_procargs(pid_t pid, char *procargs, size_t argmax) { mib[2] = pid; if (sysctl(mib, 3, procargs, &argmax, NULL, 0) < 0) { + if (psutil_pid_exists(pid) == 0) { + NoSuchProcess(""); + return 1; + } // In case of zombie process we'll get EINVAL. We translate it // to NSP and _psosx.py will translate it to ZP. - if ((errno == EINVAL) && (psutil_pid_exists(pid))) - NoSuchProcess("sysctl"); - else if (errno == EIO) { - psutil_debug("EIO, pid_exists() = %i\n", psutil_pid_exists(pid)); - PyErr_SetFromOSErrnoWithSyscall("sysctl(KERN_PROCARGS2)"); + if (errno == EINVAL) { + psutil_debug("sysctl(KERN_PROCARGS2) -> EINVAL translated to NSP"); + NoSuchProcess("sysctl(KERN_PROCARGS2) -> EINVAL"); + return 1; + } + // There's nothing we can do other than raising AD. + if (errno == EIO) { + psutil_debug("sysctl(KERN_PROCARGS2) -> EIO translated to AD"); + AccessDenied("sysctl(KERN_PROCARGS2) -> EIO"); + return 1; } - else - PyErr_SetFromOSErrnoWithSyscall("sysctl(KERN_PROCARGS2)"); + PyErr_SetFromOSErrnoWithSyscall("sysctl(KERN_PROCARGS2)"); return 1; } return 0; |