Skip to content

Commit

Permalink
give more context to OSError exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Oct 14, 2024
1 parent 4f2841c commit 023d325
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions psutil/arch/openbsd/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ psutil_kinfo_proc(pid_t pid, struct kinfo_proc *proc) {

ret = sysctl((int*)mib, 6, proc, &size, NULL, 0);
if (ret == -1) {
PyErr_SetFromErrno(PyExc_OSError);
psutil_PyErr_SetFromOSErrnoWithSyscall("sysctl(kinfo_proc)");
return -1;
}
// sysctl stores 0 in the size if we can't find the process information.
Expand Down Expand Up @@ -69,7 +69,7 @@ kinfo_getfile(pid_t pid, int* cnt) {

/* get the size of what would be returned */
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
PyErr_SetFromErrno(PyExc_OSError);
psutil_PyErr_SetFromOSErrnoWithSyscall("sysctl(kinfo_file) (1/2)");
return NULL;
}
if ((kf = malloc(len)) == NULL) {
Expand All @@ -79,7 +79,7 @@ kinfo_getfile(pid_t pid, int* cnt) {
mib[5] = (int)(len / sizeof(struct kinfo_file));
if (sysctl(mib, 6, kf, &len, NULL, 0) < 0) {
free(kf);
PyErr_SetFromErrno(PyExc_OSError);
psutil_PyErr_SetFromOSErrnoWithSyscall("sysctl(kinfo_file) (2/2)");
return NULL;
}

Expand Down

0 comments on commit 023d325

Please sign in to comment.