summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-06-14 16:53:17 +0800
committerGitHub <noreply@github.com>2019-06-14 16:53:17 +0800
commit6bb5a30dbf8335db8d9b8c4e81d652f055deea6a (patch)
tree842fb7f6fe415207f8bff4b3876ae538ed740a69
parent5f4287d17fc6aa2643c4c6e3589c12abd0f1ded9 (diff)
downloadpsutil-6bb5a30dbf8335db8d9b8c4e81d652f055deea6a.tar.gz
[NetBSD] cmdline() raise ZombieProcess when unable to decode chars (#1536)
* bug #1536 / NetBSD / cmdline: treat EINVAL as 'return []' This happens with unicode test, meaning the C routine it's unable to decode the unicode chars. Also, fix a bug introduced in 1530 (C impl of cwd()) which does not take ENOENT into account.
-rw-r--r--HISTORY.rst2
-rw-r--r--psutil/_psbsd.py7
-rw-r--r--psutil/arch/netbsd/specific.c5
3 files changed, 9 insertions, 5 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 044b7bc0..1f83b02c 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -11,6 +11,8 @@ XXXX-XX-XX
(patch by Arnon Yaari)
- 1535_: 'type' and 'family' fields returned by net_connections() are not
always turned into enums.
+- 1536_: [NetBSD] process cmdline() erroneously raise ZombieProcess error if
+ cmdline has non encodable chars.
5.6.3
=====
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 9964f5ff..978ad6c8 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -648,10 +648,9 @@ class Process(object):
return cext.proc_cmdline(self.pid)
except OSError as err:
if err.errno == errno.EINVAL:
- if not pid_exists(self.pid):
- raise NoSuchProcess(self.pid, self._name)
- else:
- raise ZombieProcess(self.pid, self._name, self._ppid)
+ # XXX: this happens with unicode tests. It means the C
+ # routine is unable to decode invalid unicode chars.
+ return []
else:
raise
else:
diff --git a/psutil/arch/netbsd/specific.c b/psutil/arch/netbsd/specific.c
index 050652c3..25adffcd 100644
--- a/psutil/arch/netbsd/specific.c
+++ b/psutil/arch/netbsd/specific.c
@@ -137,7 +137,10 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
ssize_t len = readlink(buf, path, sizeof(path) - 1);
free(buf);
if (len == -1) {
- PyErr_SetFromErrno(PyExc_OSError);
+ if (errno == ENOENT)
+ NoSuchProcess("");
+ else
+ PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
path[len] = '\0';