From d43ee3003350df56c6d1a96dac9784f064daad46 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Fri, 24 Nov 2017 15:05:33 +0100 Subject: [PATCH] fix #1181: raise AD if task_for_pid() fails with 5 and errno == ENOENT --- HISTORY.rst | 1 + psutil/_psutil_osx.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index fb3311bb3..430fb5e4f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -17,6 +17,7 @@ - 1169_: [Linux] users() "hostname" returns username instead. (patch by janderbrain) - 1172_: [Windows] `make test` does not work. +- 1181_: [OSX] Process.memory_maps() may raise ENOENT. 5.4.1 ===== diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index fef61ca85..55dd64ca5 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -338,8 +338,16 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) { err = task_for_pid(mach_task_self(), (pid_t)pid, &task); if (err != KERN_SUCCESS) { - psutil_debug("task_for_pid() failed"); // TODO temporary - psutil_raise_for_pid(pid, "task_for_pid()"); + if ((err == 5) && (errno == ENOENT)) { + // See: https://github.com/giampaolo/psutil/issues/1181 + psutil_debug("task_for_pid(MACH_PORT_NULL) failed; err=%i, " + "errno=%i, msg='%s'\n", err, errno, + mach_error_string(err)); + AccessDenied(""); + } + else { + psutil_raise_for_pid(pid, "task_for_pid(MACH_PORT_NULL)"); + } goto error; }