diff options
author | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-03-16 10:45:30 +0000 |
---|---|---|
committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-03-16 10:45:30 +0000 |
commit | 6b63fe1f6a8e9e50ef41cd71ff372935c8949733 (patch) | |
tree | 17e4c89a0c0623da4bc576cc34248c5f8882e8b6 | |
parent | bfbceea1bd99eb90cdd5c75b68b2e3a158a289f8 (diff) | |
download | psutil-6b63fe1f6a8e9e50ef41cd71ff372935c8949733.tar.gz |
Fix issue 366 (BSD): get_memory_maps(), get_num_fds(), get_open_files() and getcwd() Process methods raise RuntimeError instead of AccessDenied.
-rw-r--r-- | HISTORY | 2 | ||||
-rw-r--r-- | psutil/_psutil_bsd.c | 8 | ||||
-rw-r--r-- | psutil/_psutil_common.c | 1 | ||||
-rw-r--r-- | psutil/arch/bsd/process_info.c | 14 |
4 files changed, 20 insertions, 5 deletions
@@ -48,6 +48,8 @@ BUG FIXES process. * #365: Process.set_nice() should check PID has not been reused by another process. + * #366: [FreeBSD] get_memory_maps(), get_num_fds(), get_open_files() and + getcwd() Process methods raise RuntimeError instead of AccessDenied. API CHANGES diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index 0ee8f3e8..26a729b7 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -730,7 +730,7 @@ get_process_open_files(PyObject* self, PyObject* args) freep = kinfo_getfile(pid, &cnt); if (freep == NULL) { - PyErr_SetFromErrno(0); + psutil_raise_ad_or_nsp(); goto error; } @@ -778,7 +778,7 @@ get_process_num_fds(PyObject* self, PyObject* args) freep = kinfo_getfile(pid, &cnt); if (freep == NULL) { - PyErr_SetFromErrno(0); + psutil_raise_ad_or_nsp(); return NULL; } free(freep); @@ -808,7 +808,7 @@ get_process_cwd(PyObject* self, PyObject* args) freep = kinfo_getfile(pid, &cnt); if (freep == NULL) { - PyErr_SetFromErrno(0); + psutil_raise_ad_or_nsp(); goto error; } @@ -1255,7 +1255,7 @@ get_process_memory_maps(PyObject* self, PyObject* args) freep = kinfo_getvmmap(pid, &cnt); if (freep == NULL) { - PyErr_SetString(PyExc_RuntimeError, "kinfo_getvmmap() failed"); + psutil_raise_ad_or_nsp(); goto error; } for (i = 0; i < cnt; i++) { diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c index 27463095..43c8434a 100644 --- a/psutil/_psutil_common.c +++ b/psutil/_psutil_common.c @@ -34,4 +34,3 @@ AccessDenied(void) { Py_XDECREF(exc); return NULL; } - diff --git a/psutil/arch/bsd/process_info.c b/psutil/arch/bsd/process_info.c index 5c173afe..268a761a 100644 --- a/psutil/arch/bsd/process_info.c +++ b/psutil/arch/bsd/process_info.c @@ -265,3 +265,17 @@ pid_exists(long pid) // otherwise return 0 for PID not found return 0; } + + +/* + * Set exception to AccessDenied if pid exists else NoSuchProcess. + */ +int +psutil_raise_ad_or_nsp(pid) { + if (pid_exists(pid) == 0) { + NoSuchProcess(); + } + else { + AccessDenied(); + } +} |