diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-10-05 23:35:09 +0200 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-10-05 23:35:09 +0200 |
| commit | 80efb76212cf7f594e79b8909df77b9966790655 (patch) | |
| tree | 4cc903ac458d4f692b50b0aa085d518beef7776f /psutil | |
| parent | ff1a204a7a3847ff2c9c2ea963202d94c418c8e8 (diff) | |
| download | psutil-80efb76212cf7f594e79b8909df77b9966790655.tar.gz | |
change wording when raising RuntimeError from C (add 'syscall' term)
Diffstat (limited to 'psutil')
| -rw-r--r-- | psutil/_psutil_bsd.c | 5 | ||||
| -rw-r--r-- | psutil/_psutil_linux.c | 2 | ||||
| -rw-r--r-- | psutil/_psutil_osx.c | 48 | ||||
| -rw-r--r-- | psutil/_psutil_sunos.c | 3 | ||||
| -rw-r--r-- | psutil/_psutil_windows.c | 9 | ||||
| -rw-r--r-- | psutil/arch/bsd/freebsd.c | 10 | ||||
| -rw-r--r-- | psutil/arch/bsd/netbsd.c | 5 | ||||
| -rw-r--r-- | psutil/arch/bsd/openbsd.c | 4 | ||||
| -rw-r--r-- | psutil/arch/windows/process_info.c | 5 |
9 files changed, 56 insertions, 35 deletions
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index 73499edf..45d069be 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -129,9 +129,12 @@ psutil_pids(PyObject *self, PyObject *args) { if (py_retlist == NULL) return NULL; + + // 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."); + "failed to retrieve process list"); goto error; } diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index e6c43518..c9be53d4 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -208,7 +208,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { while ((entry = getmntent(file))) { if (entry == NULL) { - PyErr_Format(PyExc_RuntimeError, "getmntent() failed"); + PyErr_Format(PyExc_RuntimeError, "getmntent() syscall failed"); goto error; } py_tuple = Py_BuildValue("(ssss)", diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index a7d4680a..296d6fb1 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -57,8 +57,10 @@ psutil_sys_vminfo(vm_statistics_data_t *vmstat) { ret = host_statistics(mport, HOST_VM_INFO, (host_info_t)vmstat, &count); if (ret != KERN_SUCCESS) { - PyErr_Format(PyExc_RuntimeError, - "host_statistics() failed: %s", mach_error_string(ret)); + PyErr_Format( + PyExc_RuntimeError, + "host_statistics(HOST_VM_INFO) syscall failed: %s", + mach_error_string(ret)); return 0; } mach_port_deallocate(mach_task_self(), mport); @@ -614,7 +616,9 @@ psutil_proc_memory_uss(PyObject *self, PyObject *args) { break; } else if (kr != KERN_SUCCESS) { - PyErr_Format(PyExc_RuntimeError, "mach_vm_region() failed"); + PyErr_Format( + PyExc_RuntimeError, + "mach_vm_region(VM_REGION_TOP_INFO) syscall failed"); return NULL; } @@ -709,7 +713,8 @@ psutil_virtual_mem(PyObject *self, PyObject *args) { if (errno != 0) PyErr_SetFromErrno(PyExc_OSError); else - PyErr_Format(PyExc_RuntimeError, "sysctl(HW_MEMSIZE) failed"); + PyErr_Format( + PyExc_RuntimeError, "sysctl(HW_MEMSIZE) syscall failed"); return NULL; } @@ -746,7 +751,8 @@ psutil_swap_mem(PyObject *self, PyObject *args) { if (errno != 0) PyErr_SetFromErrno(PyExc_OSError); else - PyErr_Format(PyExc_RuntimeError, "sysctl(VM_SWAPUSAGE) failed"); + PyErr_Format( + PyExc_RuntimeError, "sysctl(VM_SWAPUSAGE) syscall failed"); return NULL; } if (!psutil_sys_vminfo(&vmstat)) @@ -774,10 +780,12 @@ psutil_cpu_times(PyObject *self, PyObject *args) { mach_port_t host_port = mach_host_self(); error = host_statistics(host_port, HOST_CPU_LOAD_INFO, (host_info_t)&r_load, &count); - if (error != KERN_SUCCESS) - return PyErr_Format(PyExc_RuntimeError, - "Error in host_statistics(): %s", - mach_error_string(error)); + if (error != KERN_SUCCESS) { + return PyErr_Format( + PyExc_RuntimeError, + "host_statistics(HOST_CPU_LOAD_INFO) syscall failed: %s", + mach_error_string(error)); + } mach_port_deallocate(mach_task_self(), host_port); return Py_BuildValue( @@ -811,8 +819,10 @@ psutil_per_cpu_times(PyObject *self, PyObject *args) { error = host_processor_info(host_port, PROCESSOR_CPU_LOAD_INFO, &cpu_count, &info_array, &info_count); if (error != KERN_SUCCESS) { - PyErr_Format(PyExc_RuntimeError, "Error in host_processor_info(): %s", - mach_error_string(error)); + PyErr_Format( + PyExc_RuntimeError, + "host_processor_info(PROCESSOR_CPU_LOAD_INFO) syscall failed: %s", + mach_error_string(error)); goto error; } mach_port_deallocate(mach_task_self(), host_port); @@ -1058,14 +1068,14 @@ psutil_proc_threads(PyObject *self, PyObject *args) { else { // otherwise throw a runtime error with appropriate error code PyErr_Format(PyExc_RuntimeError, - "task_info(TASK_BASIC_INFO) failed"); + "task_info(TASK_BASIC_INFO) syscall failed"); } goto error; } err = task_threads(task, &thread_list, &thread_count); if (err != KERN_SUCCESS) { - PyErr_Format(PyExc_RuntimeError, "task_threads() failed"); + PyErr_Format(PyExc_RuntimeError, "task_threads() syscall failed"); goto error; } @@ -1076,7 +1086,7 @@ psutil_proc_threads(PyObject *self, PyObject *args) { (thread_info_t)thinfo_basic, &thread_info_count); if (kr != KERN_SUCCESS) { PyErr_Format(PyExc_RuntimeError, - "thread_info() with flag THREAD_BASIC_INFO failed"); + "thread_info(THREAD_BASIC_INFO) syscall failed"); goto error; } @@ -1560,8 +1570,8 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) { if (IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(kIOMediaClass), &disk_list) != kIOReturnSuccess) { - PyErr_SetString(PyExc_RuntimeError, - "unable to get the list of disks."); + PyErr_SetString( + PyExc_RuntimeError, "unable to get the list of disks."); goto error; } @@ -1767,8 +1777,10 @@ psutil_cpu_stats(PyObject *self, PyObject *args) { ret = host_statistics(mport, HOST_VM_INFO, (host_info_t)&vmstat, &count); if (ret != KERN_SUCCESS) { - PyErr_Format(PyExc_RuntimeError, - "host_statistics() failed: %s", mach_error_string(ret)); + PyErr_Format( + PyExc_RuntimeError, + "host_statistics(HOST_VM_INFO) failed: %s", + mach_error_string(ret)); return NULL; } mach_port_deallocate(mach_task_self(), mport); diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c index 0ceec54c..e98ff7f2 100644 --- a/psutil/_psutil_sunos.c +++ b/psutil/_psutil_sunos.c @@ -71,7 +71,8 @@ psutil_file_to_struct(char *path, void *fstruct, size_t size) { } if (nbytes != size) { close(fd); - PyErr_SetString(PyExc_RuntimeError, "structure size mismatch"); + PyErr_SetString( + PyExc_RuntimeError, "read() file structure size mismatch"); return 0; } close(fd); diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 4df88864..1a4172c7 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -174,7 +174,8 @@ psutil_get_nic_addresses() { } while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (attempts < 3)); if (dwRetVal != NO_ERROR) { - PyErr_SetString(PyExc_RuntimeError, "GetAdaptersAddresses() failed."); + PyErr_SetString( + PyExc_RuntimeError, "GetAdaptersAddresses() syscall failed."); return NULL; } @@ -2093,7 +2094,7 @@ psutil_proc_io_priority_set(PyObject *self, PyObject *args) { if (NtSetInformationProcess == NULL) { PyErr_SetString(PyExc_RuntimeError, - "couldn't get NtSetInformationProcess"); + "couldn't get NtSetInformationProcess syscall"); return NULL; } @@ -2325,7 +2326,7 @@ psutil_net_io_counters(PyObject *self, PyObject *args) { if (dwRetVal != NO_ERROR) { PyErr_SetString(PyExc_RuntimeError, - "GetIfEntry() or GetIfEntry2() failed."); + "GetIfEntry() or GetIfEntry2() syscalls failed."); goto error; } @@ -3233,7 +3234,7 @@ psutil_net_if_stats(PyObject *self, PyObject *args) { // Make a second call to GetIfTable to get the actual // data we want. if ((dwRetVal = GetIfTable(pIfTable, &dwSize, FALSE)) != NO_ERROR) { - PyErr_SetString(PyExc_RuntimeError, "GetIfTable() failed"); + PyErr_SetString(PyExc_RuntimeError, "GetIfTable() syscall failed"); goto error; } diff --git a/psutil/arch/bsd/freebsd.c b/psutil/arch/bsd/freebsd.c index 54bc0df6..c9312960 100644 --- a/psutil/arch/bsd/freebsd.c +++ b/psutil/arch/bsd/freebsd.c @@ -508,13 +508,14 @@ psutil_swap_mem(PyObject *self, PyObject *args) { kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open failed"); if (kd == NULL) { - PyErr_SetString(PyExc_RuntimeError, "kvm_open failed"); + PyErr_SetString(PyExc_RuntimeError, "kvm_open() syscall failed"); return NULL; } if (kvm_getswapinfo(kd, kvmsw, 1, 0) < 0) { kvm_close(kd); - PyErr_SetString(PyExc_RuntimeError, "kvm_getswapinfo failed"); + PyErr_SetString(PyExc_RuntimeError, + "kvm_getswapinfo() syscall failed"); return NULL; } @@ -699,7 +700,8 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) { if (py_retdict == NULL) return NULL; if (devstat_checkversion(NULL) < 0) { - PyErr_Format(PyExc_RuntimeError, "devstat_checkversion() failed"); + PyErr_Format(PyExc_RuntimeError, + "devstat_checkversion() syscall failed"); goto error; } @@ -711,7 +713,7 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) { bzero(stats.dinfo, sizeof(struct devinfo)); if (devstat_getdevs(NULL, &stats) == -1) { - PyErr_Format(PyExc_RuntimeError, "devstat_getdevs() failed"); + PyErr_Format(PyExc_RuntimeError, "devstat_getdevs() syscall failed"); goto error; } diff --git a/psutil/arch/bsd/netbsd.c b/psutil/arch/bsd/netbsd.c index 85258870..5645e716 100644 --- a/psutil/arch/bsd/netbsd.c +++ b/psutil/arch/bsd/netbsd.c @@ -287,13 +287,14 @@ psutil_get_proc_list(kinfo_proc **procList, size_t *procCount) { kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf); if (kd == NULL) { - PyErr_Format(PyExc_RuntimeError, "kvm_openfiles() failed: %s", errbuf); + PyErr_Format( + PyExc_RuntimeError, "kvm_openfiles() syscall failed: %s", errbuf); return errno; } result = kvm_getproc2(kd, KERN_PROC_ALL, 0, sizeof(kinfo_proc), &cnt); if (result == NULL) { - PyErr_Format(PyExc_RuntimeError, "kvm_getproc2() failed"); + PyErr_Format(PyExc_RuntimeError, "kvm_getproc2() syscall failed"); kvm_close(kd); return errno; } diff --git a/psutil/arch/bsd/openbsd.c b/psutil/arch/bsd/openbsd.c index af67092f..dfa8999b 100644 --- a/psutil/arch/bsd/openbsd.c +++ b/psutil/arch/bsd/openbsd.c @@ -247,7 +247,7 @@ psutil_proc_threads(PyObject *self, PyObject *args) { if (strstr(errbuf, "Permission denied") != NULL) AccessDenied(); else - PyErr_Format(PyExc_RuntimeError, "kvm_openfiles() failed"); + PyErr_Format(PyExc_RuntimeError, "kvm_openfiles() syscall failed"); goto error; } @@ -258,7 +258,7 @@ psutil_proc_threads(PyObject *self, PyObject *args) { if (strstr(errbuf, "Permission denied") != NULL) AccessDenied(); else - PyErr_Format(PyExc_RuntimeError, "kvm_getprocs() failed"); + PyErr_Format(PyExc_RuntimeError, "kvm_getprocs() syscall failed"); goto error; } diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c index c1272581..5b0b7726 100644 --- a/psutil/arch/windows/process_info.c +++ b/psutil/arch/windows/process_info.c @@ -615,7 +615,7 @@ static int psutil_get_process_data(long pid, src = procParameters.CommandLine.Buffer; size = procParameters.CommandLine.Length; break; - case KIND_CWD: + case KIND_CWD: src = procParameters.CurrentDirectoryPath.Buffer; size = procParameters.CurrentDirectoryPath.Length; break; @@ -830,7 +830,8 @@ psutil_get_proc_info(DWORD pid, PSYSTEM_PROCESS_INFORMATION *retProcess, } if (status != 0) { - PyErr_Format(PyExc_RuntimeError, "NtQuerySystemInformation() failed"); + PyErr_Format( + PyExc_RuntimeError, "NtQuerySystemInformation() syscall failed"); goto error; } |
