summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-10-19 01:23:04 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-10-19 01:23:04 +0200
commitb184c486bf9f9af150c69103c86d2bf10c7bdf02 (patch)
tree2823508f1cfa65e097cc61fe00489ebb87dac5bb
parentc7ddad2dcd5ae2af06f9960507a0cd59907c95db (diff)
downloadpsutil-b184c486bf9f9af150c69103c86d2bf10c7bdf02.tar.gz
#910: [OSX / BSD] in case of error, psutil.pids() raised RuntimeError instead of the original OSError exception.
-rw-r--r--HISTORY.rst2
-rw-r--r--psutil/_psutil_bsd.c9
-rw-r--r--psutil/_psutil_osx.c9
-rw-r--r--psutil/arch/bsd/freebsd.c6
-rw-r--r--psutil/arch/bsd/netbsd.c1
-rw-r--r--psutil/arch/osx/process_info.c11
6 files changed, 24 insertions, 14 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 3096c5dd..26acad85 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -35,6 +35,8 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
instead of OSError and RuntimeError.
- #909: [OSX] Process open_files() and connections() methods may raise
OSError with no exception set if process is gone.
+- #910: [OSX / BSD] in case of error, psutil.pids() raised RuntimeError instead
+ of the original OSError exception.
- #916: [OSX] fix many compilation warnings.
- #918: [NetBSD] all memory metrics were wrong.
- #921: psutil.Popen now defines a __del__ special method which calls the
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index 45d069be..3a73275f 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -133,8 +133,13 @@ psutil_pids(PyObject *self, PyObject *args) {
// TODO: RuntimeError is inappropriate here; we could return the
// original error instead.
if (psutil_get_proc_list(&proclist, &num_processes) != 0) {
- PyErr_SetString(PyExc_RuntimeError,
- "failed to retrieve process list");
+ if (errno != 0) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ }
+ else {
+ PyErr_SetString(PyExc_RuntimeError,
+ "failed to retrieve process list");
+ }
goto error;
}
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c
index 06b4ba25..851b8f6a 100644
--- a/psutil/_psutil_osx.c
+++ b/psutil/_psutil_osx.c
@@ -84,8 +84,13 @@ psutil_pids(PyObject *self, PyObject *args) {
return NULL;
if (psutil_get_proc_list(&proclist, &num_processes) != 0) {
- PyErr_SetString(PyExc_RuntimeError,
- "failed to retrieve process list.");
+ if (errno != 0) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ }
+ else {
+ PyErr_SetString(PyExc_RuntimeError,
+ "failed to retrieve process list");
+ }
goto error;
}
diff --git a/psutil/arch/bsd/freebsd.c b/psutil/arch/bsd/freebsd.c
index c9312960..456a50aa 100644
--- a/psutil/arch/bsd/freebsd.c
+++ b/psutil/arch/bsd/freebsd.c
@@ -92,10 +92,8 @@ psutil_get_proc_list(struct kinfo_proc **procList, size_t *procCount) {
int err;
struct kinfo_proc *result;
int done;
- static const int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0 };
- // Declaring name as const requires us to cast it when passing it to
- // sysctl because the prototype doesn't include the const modifier.
- size_t length;
+ int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0 };
+ size_t length;
assert( procList != NULL);
assert(*procList == NULL);
diff --git a/psutil/arch/bsd/netbsd.c b/psutil/arch/bsd/netbsd.c
index 9797fa7e..2cf2ef22 100644
--- a/psutil/arch/bsd/netbsd.c
+++ b/psutil/arch/bsd/netbsd.c
@@ -524,6 +524,7 @@ psutil_proc_num_fds(PyObject *self, PyObject *args) {
PyObject *
psutil_per_cpu_times(PyObject *self, PyObject *args) {
+ // XXX: why static?
static int maxcpus;
int mib[3];
int ncpu;
diff --git a/psutil/arch/osx/process_info.c b/psutil/arch/osx/process_info.c
index 2169cdc8..4b0b458b 100644
--- a/psutil/arch/osx/process_info.c
+++ b/psutil/arch/osx/process_info.c
@@ -33,12 +33,11 @@
*/
int
psutil_get_proc_list(kinfo_proc **procList, size_t *procCount) {
- // Declaring mib as const requires use of a cast since the
- // sysctl prototype doesn't include the const modifier.
- static const int mib3[3] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
- size_t size, size2;
- void *ptr;
- int err, lim = 8; // some limit
+ int mib3[3] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
+ size_t size, size2;
+ void *ptr;
+ int err;
+ int lim = 8; // some limit
assert( procList != NULL);
assert(*procList == NULL);