diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-24 09:55:52 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-24 09:55:52 -0800 |
commit | 7a2572268168e96c8841ca83ab1a89735ec02c3a (patch) | |
tree | 656a58683c5c48308152b302f1a31c4c82e74106 /psutil/_psutil_osx.c | |
parent | 88beee9e0d169e979a3027bf9e61c59ccc1ad6e3 (diff) | |
download | psutil-7a2572268168e96c8841ca83ab1a89735ec02c3a.tar.gz |
#1428 in case of error, show the C syscall which caused it
Diffstat (limited to 'psutil/_psutil_osx.c')
-rw-r--r-- | psutil/_psutil_osx.c | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index be08de55..1b98cc58 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -141,31 +141,22 @@ psutil_pids(PyObject *self, PyObject *args) { if (py_retlist == NULL) return NULL; - if (psutil_get_proc_list(&proclist, &num_processes) != 0) { - if (errno != 0) { - PyErr_SetFromErrno(PyExc_OSError); - } - else { - PyErr_SetString(PyExc_RuntimeError, - "failed to retrieve process list"); - } + if (psutil_get_proc_list(&proclist, &num_processes) != 0) goto error; - } - if (num_processes > 0) { - // save the address of proclist so we can free it later - orig_address = proclist; - for (idx = 0; idx < num_processes; idx++) { - py_pid = Py_BuildValue("i", proclist->kp_proc.p_pid); - if (! py_pid) - goto error; - if (PyList_Append(py_retlist, py_pid)) - goto error; - Py_DECREF(py_pid); - proclist++; - } - free(orig_address); + // save the address of proclist so we can free it later + orig_address = proclist; + for (idx = 0; idx < num_processes; idx++) { + py_pid = Py_BuildValue("i", proclist->kp_proc.p_pid); + if (! py_pid) + goto error; + if (PyList_Append(py_retlist, py_pid)) + goto error; + Py_DECREF(py_pid); + proclist++; } + free(orig_address); + return py_retlist; error: @@ -622,8 +613,10 @@ psutil_proc_memory_uss(PyObject *self, PyObject *args) { return NULL; len = sizeof(cpu_type); - if (sysctlbyname("sysctl.proc_cputype", &cpu_type, &len, NULL, 0) != 0) - return PyErr_SetFromErrno(PyExc_OSError); + if (sysctlbyname("sysctl.proc_cputype", &cpu_type, &len, NULL, 0) != 0) { + return PyErr_SetFromOSErrnoWithSyscall( + "sysctlbyname('sysctl.proc_cputype')"); + } // Roughly based on libtop_update_vm_regions in // http://www.opensource.apple.com/source/top/top-100.1.2/libtop.c @@ -863,12 +856,18 @@ psutil_cpu_freq(PyObject *self, PyObject *args) { int64_t max; size_t size = sizeof(int64_t); - if (sysctlbyname("hw.cpufrequency", &curr, &size, NULL, 0)) - return PyErr_SetFromErrno(PyExc_OSError); - if (sysctlbyname("hw.cpufrequency_min", &min, &size, NULL, 0)) - return PyErr_SetFromErrno(PyExc_OSError); - if (sysctlbyname("hw.cpufrequency_max", &max, &size, NULL, 0)) - return PyErr_SetFromErrno(PyExc_OSError); + if (sysctlbyname("hw.cpufrequency", &curr, &size, NULL, 0)) { + return PyErr_SetFromOSErrnoWithSyscall( + "sysctlbyname('hw.cpufrequency')"); + } + if (sysctlbyname("hw.cpufrequency_min", &min, &size, NULL, 0)) { + return PyErr_SetFromOSErrnoWithSyscall( + "sysctlbyname('hw.cpufrequency_min')"); + } + if (sysctlbyname("hw.cpufrequency_max", &max, &size, NULL, 0)) { + return PyErr_SetFromOSErrnoWithSyscall( + "sysctlbyname('hw.cpufrequency_max')"); + } return Py_BuildValue( "KKK", @@ -1370,7 +1369,7 @@ psutil_proc_connections(PyObject *self, PyObject *args) { // check for inet_ntop failures if (errno != 0) { - PyErr_SetFromErrno(PyExc_OSError); + PyErr_SetFromOSErrnoWithSyscall("inet_ntop()"); goto error; } |