2023-09-12 03:36:48 +00:00
|
|
|
Index: psutil/_psbsd.py
|
|
|
|
--- psutil/_psbsd.py.orig
|
|
|
|
+++ psutil/_psbsd.py
|
|
|
|
@@ -2,7 +2,7 @@
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
-"""FreeBSD, OpenBSD and NetBSD platforms implementation."""
|
|
|
|
+"""FreeBSD, OpenBSD, SecBSD and NetBSD platforms implementation."""
|
|
|
|
|
|
|
|
import contextlib
|
|
|
|
import errno
|
|
|
|
@@ -19,6 +19,7 @@ from . import _psutil_posix as cext_posix
|
|
|
|
from ._common import FREEBSD
|
|
|
|
from ._common import NETBSD
|
|
|
|
from ._common import OPENBSD
|
|
|
|
+from ._common import SECBSD
|
|
|
|
from ._common import AccessDenied
|
|
|
|
from ._common import NoSuchProcess
|
|
|
|
from ._common import ZombieProcess
|
2024-05-26 03:08:12 +00:00
|
|
|
@@ -52,7 +53,7 @@ if FREEBSD:
|
2023-09-12 03:36:48 +00:00
|
|
|
cext.SWAIT: _common.STATUS_WAITING,
|
|
|
|
cext.SLOCK: _common.STATUS_LOCKED,
|
|
|
|
}
|
|
|
|
-elif OPENBSD:
|
|
|
|
+elif OPENBSD or SECBSD:
|
|
|
|
PROC_STATUSES = {
|
|
|
|
cext.SIDL: _common.STATUS_IDLE,
|
|
|
|
cext.SSLEEP: _common.STATUS_SLEEPING,
|
2024-05-26 03:08:12 +00:00
|
|
|
@@ -281,7 +282,7 @@ def cpu_count_logical():
|
2023-09-12 03:36:48 +00:00
|
|
|
return cext.cpu_count_logical()
|
|
|
|
|
|
|
|
|
|
|
|
-if OPENBSD or NETBSD:
|
2024-05-26 03:08:12 +00:00
|
|
|
+if OPENBSD or SECBSD or NETBSD:
|
|
|
|
|
2023-09-12 03:36:48 +00:00
|
|
|
def cpu_count_cores():
|
|
|
|
# OpenBSD and NetBSD do not implement this.
|
2024-05-26 03:08:12 +00:00
|
|
|
@@ -339,7 +340,7 @@ def cpu_stats():
|
2023-09-12 03:36:48 +00:00
|
|
|
for line in f:
|
|
|
|
if line.startswith(b'intr'):
|
|
|
|
intrs = int(line.split()[1])
|
|
|
|
- elif OPENBSD:
|
|
|
|
+ elif OPENBSD or SECBSD:
|
|
|
|
# Note: the C ext is returning some metrics we are not exposing:
|
|
|
|
# traps, faults and forks.
|
2024-05-26 03:08:12 +00:00
|
|
|
ctxsw, intrs, soft_intrs, syscalls, traps, faults, forks = (
|
|
|
|
@@ -374,7 +375,7 @@ if FREEBSD:
|
2023-09-12 03:36:48 +00:00
|
|
|
ret.append(_common.scpufreq(current, min_freq, max_freq))
|
|
|
|
return ret
|
2024-05-26 03:08:12 +00:00
|
|
|
|
2023-09-12 03:36:48 +00:00
|
|
|
-elif OPENBSD:
|
|
|
|
+elif OPENBSD or SECBSD:
|
2024-05-26 03:08:12 +00:00
|
|
|
|
2023-09-12 03:36:48 +00:00
|
|
|
def cpu_freq():
|
|
|
|
curr = float(cext.cpu_freq())
|
2024-05-26 03:08:12 +00:00
|
|
|
@@ -450,7 +451,7 @@ def net_connections(kind):
|
|
|
|
families, types = conn_tmap[kind]
|
|
|
|
ret = set()
|
2023-09-12 03:36:48 +00:00
|
|
|
|
|
|
|
- if OPENBSD:
|
|
|
|
+ if OPENBSD or SECBSD:
|
2024-05-26 03:08:12 +00:00
|
|
|
rawlist = cext.net_connections(-1, families, types)
|
|
|
|
elif NETBSD:
|
|
|
|
rawlist = cext.net_connections(-1, kind)
|
|
|
|
@@ -525,7 +526,7 @@ def users():
|
2023-09-12 03:36:48 +00:00
|
|
|
for item in rawlist:
|
|
|
|
user, tty, hostname, tstamp, pid = item
|
|
|
|
if pid == -1:
|
|
|
|
- assert OPENBSD
|
|
|
|
+ assert SECBSD
|
|
|
|
pid = None
|
|
|
|
if tty == '~':
|
|
|
|
continue # reboot or shutdown
|
2024-05-26 03:08:12 +00:00
|
|
|
@@ -554,14 +555,14 @@ def _pid_0_exists():
|
2023-09-12 03:36:48 +00:00
|
|
|
def pids():
|
|
|
|
"""Returns a list of PIDs currently running on the system."""
|
|
|
|
ret = cext.pids()
|
|
|
|
- if OPENBSD and (0 not in ret) and _pid_0_exists():
|
|
|
|
+ if SECBSD and (0 not in ret) and _pid_0_exists():
|
|
|
|
# On OpenBSD the kernel does not return PID 0 (neither does
|
|
|
|
# ps) but it's actually querable (Process(0) will succeed).
|
|
|
|
ret.insert(0, 0)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
-if OPENBSD or NETBSD:
|
2024-05-26 03:08:12 +00:00
|
|
|
+if OPENBSD or SECBSD or NETBSD:
|
|
|
|
|
2023-09-12 03:36:48 +00:00
|
|
|
def pid_exists(pid):
|
|
|
|
"""Return True if pid exists."""
|
2024-05-26 03:08:12 +00:00
|
|
|
@@ -690,7 +691,7 @@ class Process:
|
2023-09-12 03:36:48 +00:00
|
|
|
|
|
|
|
@wrap_exceptions
|
|
|
|
def cmdline(self):
|
|
|
|
- if OPENBSD and self.pid == 0:
|
|
|
|
+ if SECBSD and self.pid == 0:
|
|
|
|
return [] # ...else it crashes
|
|
|
|
elif NETBSD:
|
2024-05-26 03:08:12 +00:00
|
|
|
# XXX - most of the times the underlying sysctl() call on
|
|
|
|
@@ -808,7 +809,7 @@ class Process:
|
2023-09-12 03:36:48 +00:00
|
|
|
for thread_id, utime, stime in rawlist:
|
|
|
|
ntuple = _common.pthread(thread_id, utime, stime)
|
|
|
|
retlist.append(ntuple)
|
|
|
|
- if OPENBSD:
|
2024-05-26 03:08:12 +00:00
|
|
|
+ if SECBSD:
|
2023-09-12 03:36:48 +00:00
|
|
|
self._assert_alive()
|
|
|
|
return retlist
|
|
|
|
|
2024-05-26 03:08:12 +00:00
|
|
|
@@ -824,7 +825,7 @@ class Process:
|
2023-09-12 03:36:48 +00:00
|
|
|
|
2024-05-26 03:08:12 +00:00
|
|
|
if NETBSD:
|
|
|
|
rawlist = cext.net_connections(self.pid, kind)
|
|
|
|
- elif OPENBSD:
|
|
|
|
+ elif SECBSD:
|
|
|
|
rawlist = cext.net_connections(self.pid, families, types)
|
|
|
|
else:
|
|
|
|
rawlist = cext.proc_connections(self.pid, families, types)
|
|
|
|
@@ -875,7 +876,7 @@ class Process:
|
2023-09-12 03:36:48 +00:00
|
|
|
"""Return process current working directory."""
|
|
|
|
# sometimes we get an empty string, in which case we turn
|
|
|
|
# it into None
|
|
|
|
- if OPENBSD and self.pid == 0:
|
|
|
|
+ if SECBSD and self.pid == 0:
|
2024-05-26 03:08:12 +00:00
|
|
|
return "" # ...else it would raise EINVAL
|
2023-09-12 03:36:48 +00:00
|
|
|
elif NETBSD or HAS_PROC_OPEN_FILES:
|
|
|
|
# FreeBSD < 8 does not support functions based on
|