Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic NetBSD support. #557

Merged
merged 26 commits into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
312442a
Add NetBSD support.
ryoon Dec 30, 2015
410a28c
Fix line length (PEP8).
0-wiz-0 Dec 30, 2015
aafe03b
Return PyErr_NoMemory(); on out-of-memory.
0-wiz-0 Dec 30, 2015
060d806
Return empty string when guessing pathname fails.
0-wiz-0 Dec 30, 2015
7911853
Move function on request from giampaolo.
0-wiz-0 Dec 30, 2015
de9d763
Call kvm_close() in error cases to avoid resource leak.
0-wiz-0 Dec 30, 2015
c81dcf5
untabify
0-wiz-0 Dec 30, 2015
15e4eef
untabify
0-wiz-0 Dec 30, 2015
968bd9d
Use // for single-line comments.
0-wiz-0 Dec 30, 2015
ff5b731
Use // for single-line comments.
0-wiz-0 Dec 30, 2015
34c2110
style: move opening brace to end of line
0-wiz-0 Dec 30, 2015
72fd357
Use PyList_New instead of Py_BuildValue("[]")
0-wiz-0 Dec 30, 2015
8b4388b
Remove trailing whitespace.
0-wiz-0 Dec 30, 2015
6d76d34
Remove unnecessary pid check.
0-wiz-0 Dec 30, 2015
3b8aeba
Remove unnecessary whitespace.
0-wiz-0 Dec 30, 2015
2d377cd
Remove unnecessary whitespace.
0-wiz-0 Dec 30, 2015
59fbfa6
Raise more exceptions.
0-wiz-0 Dec 30, 2015
d95d720
Initialize pointer so that free() does not free random memory addresses.
0-wiz-0 Dec 30, 2015
e867d78
Return exceptions in more cases.
0-wiz-0 Dec 30, 2015
7178b30
Add missing free().
0-wiz-0 Dec 30, 2015
319b4aa
Move free() to correct place.
0-wiz-0 Dec 31, 2015
0d532f8
Remove duplicate case statement.
0-wiz-0 Dec 31, 2015
db60ef7
Improve reference counting.
0-wiz-0 Dec 31, 2015
dce014c
Fix two compilation warnings.
0-wiz-0 Dec 31, 2015
ed09035
Check arguments first before using it.
0-wiz-0 Jan 2, 2016
343d21b
Move check earlier per a comment from giampaolo.
0-wiz-0 Jan 2, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
elif sys.platform.startswith("darwin"):
from . import _psosx as _psplatform

elif sys.platform.startswith("freebsd") or sys.platform.startswith("openbsd"):
elif sys.platform.startswith("freebsd") or sys.platform.startswith("openbsd") \
or sys.platform.startswith("netbsd"):
from . import _psbsd as _psplatform

elif sys.platform.startswith("sunos"):
Expand Down
41 changes: 36 additions & 5 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

FREEBSD = sys.platform.startswith("freebsd")
OPENBSD = sys.platform.startswith("openbsd")
NETBSD = sys.platform.startswith("netbsd")

if FREEBSD:
PROC_STATUSES = {
Expand Down Expand Up @@ -60,6 +61,15 @@
cext.SRUN: _common.STATUS_WAKING,
cext.SONPROC: _common.STATUS_RUNNING,
}
elif NETBSD:
PROC_STATUSES = {
cext.SIDL: _common.STATUS_IDLE,
cext.SACTIVE: _common.STATUS_RUNNING,
cext.SDYING: _common.STATUS_ZOMBIE,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmm I'm not so sure about this. Also can't find any documentation. Have you ever bumped into this status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The process states in NetBSD are DYING -> DEAD -> ZOMBIE. What should we classify DYING as?

cext.SSTOP: _common.STATUS_STOPPED,
cext.SZOMB: _common.STATUS_ZOMBIE,
cext.SDEAD: _common.STATUS_DEAD,
}

TCP_STATUSES = {
cext.TCPS_ESTABLISHED: _common.CONN_ESTABLISHED,
Expand All @@ -76,7 +86,10 @@
cext.PSUTIL_CONN_NONE: _common.CONN_NONE,
}

PAGESIZE = os.sysconf("SC_PAGE_SIZE")
if NETBSD:
PAGESIZE = os.sysconf("SC_PAGESIZE")
else:
PAGESIZE = os.sysconf("SC_PAGE_SIZE")
AF_LINK = cext_posix.AF_LINK

# extend base mem ntuple with BSD-specific memory metrics
Expand Down Expand Up @@ -156,9 +169,9 @@ def cpu_count_logical():
return cext.cpu_count_logical()


if OPENBSD:
if OPENBSD or NETBSD:
def cpu_count_physical():
# OpenBSD does not implement this.
# OpenBSD and NetBSD do not implement this.
return 1 if cpu_count_logical() == 1 else None
else:
def cpu_count_physical():
Expand Down Expand Up @@ -273,7 +286,7 @@ def net_if_stats():
return ret


if OPENBSD:
if OPENBSD or NETBSD:
def pid_exists(pid):
exists = _psposix.pid_exists(pid)
if not exists:
Expand Down Expand Up @@ -333,7 +346,7 @@ def name(self):

@wrap_exceptions
def exe(self):
if FREEBSD:
if FREEBSD or NETBSD:
return cext.proc_exe(self.pid)
else:
# exe cannot be determined on OpenBSD; references:
Expand Down Expand Up @@ -426,6 +439,24 @@ def connections(self, kind='inet'):
if kind not in conn_tmap:
raise ValueError("invalid %r kind argument; choose between %s"
% (kind, ', '.join([repr(x) for x in conn_tmap])))

if NETBSD:
families, types = conn_tmap[kind]
ret = set()
rawlist = cext.proc_connections(self.pid)
for item in rawlist:
fd, fam, type, laddr, raddr, status = item
if fam in families and type in types:
try:
status = TCP_STATUSES[status]
except KeyError:
status = TCP_STATUSES[cext.PSUTIL_CONN_NONE]
fam = sockfam_to_enum(fam)
type = socktype_to_enum(type)
nt = _common.pconn(fd, fam, type, laddr, raddr, status)
ret.add(nt)
return list(ret)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved down, after the if kind not in conn_tmap check which raises ValueError

families, types = conn_tmap[kind]
rawlist = cext.proc_connections(self.pid, families, types)
ret = []
Expand Down
Loading