diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-12-29 02:08:48 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-12-29 02:08:48 +0100 |
commit | d8a8a85997bd59b720dd7456ebc1835d0e9dcd9b (patch) | |
tree | 6fb242cbdcf4c407fea3dbe2f78dff49fd62f8e9 | |
parent | 8687a11697865febb033edcac7d130c87425464e (diff) | |
download | psutil-d8a8a85997bd59b720dd7456ebc1835d0e9dcd9b.tar.gz |
Fix #1512 proc connections() fails with EOPNOTSUPP
...on macOS. Just occurs sometimes for 1 socket only. Ignore the error
and continue.
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rw-r--r-- | HISTORY.rst | 2 | ||||
-rw-r--r-- | psutil/_psutil_osx.c | 16 |
2 files changed, 12 insertions, 6 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index 9f5281f9..a33f5eb3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -9,6 +9,8 @@ XXXX-XX-XX - 1456_: [macOS] psutil.cpu_freq()'s min and max are set to 0 if can't be determined (instead of crashing). +- 1512_: [macOS] sometimes Process.connections() will crash with EOPNOTSUPP + for one connection; this is now ignored. - 1892_: [macOS] psutil.cpu_freq() broken on Apple M1. 5.8.0 diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index 62a95774..5a77de14 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -1027,9 +1027,18 @@ psutil_proc_connections(PyObject *self, PyObject *args) { PROC_PIDFDSOCKETINFO, &si, sizeof(si)); // --- errors checking - if ((nb <= 0) || (nb < sizeof(si))) { + if ((nb <= 0) || (nb < sizeof(si)) || (errno != 0)) { if (errno == EBADF) { // let's assume socket has been closed + psutil_debug("proc_pidfdinfo(PROC_PIDFDSOCKETINFO) -> " + "EBADF (ignored)"); + continue; + } + else if (errno == EOPNOTSUPP) { + // may happen sometimes, see: + // https://github.com/giampaolo/psutil/issues/1512 + psutil_debug("proc_pidfdinfo(PROC_PIDFDSOCKETINFO) -> " + "EOPNOTSUPP (ignored)"); continue; } else { @@ -1063,11 +1072,6 @@ psutil_proc_connections(PyObject *self, PyObject *args) { if (inseq == 0) continue; - if (errno != 0) { - PyErr_SetFromErrno(PyExc_OSError); - goto error; - } - if ((family == AF_INET) || (family == AF_INET6)) { if (family == AF_INET) { inet_ntop(AF_INET, |