Skip to content

Commit

Permalink
Fix #2308, OpenBSD: Process.threads() always fail with AccessDenied.
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Oct 1, 2023
1 parent 0c0840a commit ed39647
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ XXXX-XX-XX
pre-emptively checked for `Process.nice()`_ (set), `Process.ionice()`_,
(set), `Process.cpu_affinity()`_ (set), `Process.rlimit()`_
(set), `Process.parent()`_.
- 2308_, [OpenBSD]: `Process.threads()`_ always fail with AccessDenied (also as
root).

5.9.5
=====
Expand Down
11 changes: 9 additions & 2 deletions psutil/arch/openbsd/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,15 @@ psutil_proc_threads(PyObject *self, PyObject *args) {

kd = kvm_openfiles(0, 0, 0, O_RDONLY, errbuf);
if (! kd) {
convert_kvm_err("kvm_openfiles()", errbuf);
goto error;
// Usually fails due to EPERM against /dev/mem. We retry with
// KVM_NO_FILES which apparently has the same effect.
// https://stackoverflow.com/questions/22369736/
psutil_debug("kvm_openfiles(O_RDONLY) failed");
kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
if (! kd) {
convert_kvm_err("kvm_openfiles()", errbuf);
goto error;
}
}

kp = kvm_getprocs(
Expand Down

0 comments on commit ed39647

Please sign in to comment.