summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-06-02 15:25:03 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-06-02 15:25:03 +0200
commit046b74786e8b9e96563f0e78ba0615060221e65b (patch)
tree211ce52ca2e46a14482f80dcf6fa0bffcaa116fd
parent6fbbe124140f810b875e1f0e431424173ff1f011 (diff)
downloadpsutil-046b74786e8b9e96563f0e78ba0615060221e65b.tar.gz
#1044: environ() was incorrectly raising AD instead of ZombieProcess
-rw-r--r--psutil/_psosx.py7
-rw-r--r--psutil/arch/osx/process_info.c13
-rwxr-xr-xpsutil/tests/test_osx.py3
3 files changed, 11 insertions, 12 deletions
diff --git a/psutil/_psosx.py b/psutil/_psosx.py
index 617ac5f5..2048c888 100644
--- a/psutil/_psosx.py
+++ b/psutil/_psosx.py
@@ -371,16 +371,13 @@ class Process(object):
@wrap_exceptions
def cmdline(self):
- if not pid_exists(self.pid):
- raise NoSuchProcess(self.pid, self._name)
with catch_zombie(self):
return cext.proc_cmdline(self.pid)
@wrap_exceptions
def environ(self):
- if not pid_exists(self.pid):
- raise NoSuchProcess(self.pid, self._name)
- return parse_environ_block(cext.proc_environ(self.pid))
+ with catch_zombie(self):
+ return parse_environ_block(cext.proc_environ(self.pid))
@wrap_exceptions
def ppid(self):
diff --git a/psutil/arch/osx/process_info.c b/psutil/arch/osx/process_info.c
index 7533e4cf..7c715be8 100644
--- a/psutil/arch/osx/process_info.c
+++ b/psutil/arch/osx/process_info.c
@@ -235,13 +235,12 @@ psutil_get_environ(long pid) {
mib[1] = KERN_PROCARGS2;
mib[2] = (pid_t)pid;
if (sysctl(mib, 3, procargs, &argmax, NULL, 0) < 0) {
- if (EINVAL == errno) {
- // EINVAL == access denied OR nonexistent PID
- if (psutil_pid_exists(pid))
- AccessDenied();
- else
- NoSuchProcess();
- }
+ // 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();
+ else
+ PyErr_SetFromErrno(PyExc_OSError);
goto error;
}
diff --git a/psutil/tests/test_osx.py b/psutil/tests/test_osx.py
index 87ea16d7..6a327e52 100755
--- a/psutil/tests/test_osx.py
+++ b/psutil/tests/test_osx.py
@@ -126,6 +126,9 @@ class TestZombieProcessAPIs(unittest.TestCase):
def test_cmdline(self):
self.assertRaises(psutil.ZombieProcess, self.p.cmdline)
+ def test_environ(self):
+ self.assertRaises(psutil.ZombieProcess, self.p.environ)
+
@unittest.skipIf(not OSX, "OSX only")
class TestSystemAPIs(unittest.TestCase):