127 lines
4.2 KiB
Text
127 lines
4.2 KiB
Text
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
|
|
@@ -51,7 +52,7 @@ if FREEBSD:
|
|
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,
|
|
@@ -250,7 +251,7 @@ def cpu_count_logical():
|
|
return cext.cpu_count_logical()
|
|
|
|
|
|
-if OPENBSD or NETBSD:
|
|
+if OPENBSD or NETBSD or SECBSD:
|
|
def cpu_count_cores():
|
|
# OpenBSD and NetBSD do not implement this.
|
|
return 1 if cpu_count_logical() == 1 else None
|
|
@@ -304,7 +305,7 @@ def cpu_stats():
|
|
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.
|
|
ctxsw, intrs, soft_intrs, syscalls, traps, faults, forks = \
|
|
@@ -336,7 +337,7 @@ if FREEBSD:
|
|
max_freq = None
|
|
ret.append(_common.scpufreq(current, min_freq, max_freq))
|
|
return ret
|
|
-elif OPENBSD:
|
|
+elif OPENBSD or SECBSD:
|
|
def cpu_freq():
|
|
curr = float(cext.cpu_freq())
|
|
return [_common.scpufreq(curr, 0.0, 0.0)]
|
|
@@ -401,7 +402,7 @@ def net_if_stats():
|
|
|
|
def net_connections(kind):
|
|
"""System-wide network connections."""
|
|
- if OPENBSD:
|
|
+ if OPENBSD or SECBSD:
|
|
ret = []
|
|
for pid in pids():
|
|
try:
|
|
@@ -492,7 +493,7 @@ def users():
|
|
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
|
|
@@ -521,14 +522,14 @@ def _pid_0_exists():
|
|
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:
|
|
+if OPENBSD or NETBSD or SECBSD:
|
|
def pid_exists(pid):
|
|
"""Return True if pid exists."""
|
|
exists = _psposix.pid_exists(pid)
|
|
@@ -653,7 +654,7 @@ class Process(object):
|
|
|
|
@wrap_exceptions
|
|
def cmdline(self):
|
|
- if OPENBSD and self.pid == 0:
|
|
+ if SECBSD and self.pid == 0:
|
|
return [] # ...else it crashes
|
|
elif NETBSD:
|
|
# XXX - most of the times the underlying sysctl() call on Net
|
|
@@ -764,7 +765,7 @@ class Process(object):
|
|
for thread_id, utime, stime in rawlist:
|
|
ntuple = _common.pthread(thread_id, utime, stime)
|
|
retlist.append(ntuple)
|
|
- if OPENBSD:
|
|
+ if OPENBSD or SECBSD:
|
|
self._assert_alive()
|
|
return retlist
|
|
|
|
@@ -797,7 +798,7 @@ class Process(object):
|
|
TCP_STATUSES)
|
|
ret.append(nt)
|
|
|
|
- if OPENBSD:
|
|
+ if OPENBSD or SECBSD:
|
|
self._assert_alive()
|
|
|
|
return ret
|
|
@@ -834,7 +835,7 @@ class Process(object):
|
|
"""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:
|
|
return None # ...else it would raise EINVAL
|
|
elif NETBSD or HAS_PROC_OPEN_FILES:
|
|
# FreeBSD < 8 does not support functions based on
|