Skip to content

Commit

Permalink
#1044: cmdline() was incorrectly raising AD instead of ZombieProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jun 2, 2017
1 parent 859c54c commit 6fbbe12
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
13 changes: 6 additions & 7 deletions psutil/arch/osx/process_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,12 @@ psutil_get_cmdline(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;
}

Expand Down
28 changes: 28 additions & 0 deletions psutil/tests/test_osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import psutil
from psutil import OSX
from psutil.tests import create_zombie_proc
from psutil.tests import get_test_subprocess
from psutil.tests import MEMORY_TOLERANCE
from psutil.tests import reap_children
Expand Down Expand Up @@ -99,6 +100,33 @@ def test_process_create_time(self):
time.strftime("%Y", time.localtime(start_psutil)))


@unittest.skipIf(not OSX, "OSX only")
class TestZombieProcessAPIs(unittest.TestCase):

@classmethod
def setUpClass(cls):
zpid = create_zombie_proc()
cls.p = psutil.Process(zpid)

@classmethod
def tearDownClass(cls):
reap_children(recursive=True)

def test_pidtask_info(self):
self.p.ppid()
self.p.uids()
self.p.gids()
self.p.terminal()
self.p.create_time()
self.p.status()

def test_exe(self):
self.assertRaises(psutil.ZombieProcess, self.p.exe)

def test_cmdline(self):
self.assertRaises(psutil.ZombieProcess, self.p.cmdline)


@unittest.skipIf(not OSX, "OSX only")
class TestSystemAPIs(unittest.TestCase):

Expand Down

0 comments on commit 6fbbe12

Please sign in to comment.