diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-10-17 03:19:21 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-10-17 03:19:21 +0200 |
commit | 239ebc19c8477893870e497fd344744cb5d964a7 (patch) | |
tree | 07e9cba5d94988754f7def5a750eb25b5b42f3c9 /psutil/_psutil_osx.c | |
parent | 0398213c561faf641f60a625a02d7df17f0d1e89 (diff) | |
download | psutil-239ebc19c8477893870e497fd344744cb5d964a7.tar.gz |
fix #1738 / osx / exe(): catch ENOENT which may occur if process is still alive but the executable file which launched it got deleted
Diffstat (limited to 'psutil/_psutil_osx.c')
-rw-r--r-- | psutil/_psutil_osx.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index fdf34d97..ee8d1c83 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -298,11 +298,21 @@ psutil_proc_exe(PyObject *self, PyObject *args) { errno = 0; ret = proc_pidpath(pid, &buf, sizeof(buf)); if (ret == 0) { - if (pid == 0) + if (pid == 0) { AccessDenied("automatically set for PID 0"); - else + return NULL; + } + else if (errno == ENOENT) { + // It may happen (file not found error) if the process is + // still alive but the executable which launched it got + // deleted, see: + // https://github.com/giampaolo/psutil/issues/1738 + return Py_BuildValue("s", ""); + } + else { psutil_raise_for_pid(pid, "proc_pidpath()"); - return NULL; + return NULL; + } } return PyUnicode_DecodeFSDefault(buf); } |