-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
312442a
Add NetBSD support.
ryoon 410a28c
Fix line length (PEP8).
0-wiz-0 aafe03b
Return PyErr_NoMemory(); on out-of-memory.
0-wiz-0 060d806
Return empty string when guessing pathname fails.
0-wiz-0 7911853
Move function on request from giampaolo.
0-wiz-0 de9d763
Call kvm_close() in error cases to avoid resource leak.
0-wiz-0 c81dcf5
untabify
0-wiz-0 15e4eef
untabify
0-wiz-0 968bd9d
Use // for single-line comments.
0-wiz-0 ff5b731
Use // for single-line comments.
0-wiz-0 34c2110
style: move opening brace to end of line
0-wiz-0 72fd357
Use PyList_New instead of Py_BuildValue("[]")
0-wiz-0 8b4388b
Remove trailing whitespace.
0-wiz-0 6d76d34
Remove unnecessary pid check.
0-wiz-0 3b8aeba
Remove unnecessary whitespace.
0-wiz-0 2d377cd
Remove unnecessary whitespace.
0-wiz-0 59fbfa6
Raise more exceptions.
0-wiz-0 d95d720
Initialize pointer so that free() does not free random memory addresses.
0-wiz-0 e867d78
Return exceptions in more cases.
0-wiz-0 7178b30
Add missing free().
0-wiz-0 319b4aa
Move free() to correct place.
0-wiz-0 0d532f8
Remove duplicate case statement.
0-wiz-0 db60ef7
Improve reference counting.
0-wiz-0 dce014c
Fix two compilation warnings.
0-wiz-0 ed09035
Check arguments first before using it.
0-wiz-0 343d21b
Move check earlier per a comment from giampaolo.
0-wiz-0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
|
||
FREEBSD = sys.platform.startswith("freebsd") | ||
OPENBSD = sys.platform.startswith("openbsd") | ||
NETBSD = sys.platform.startswith("netbsd") | ||
|
||
if FREEBSD: | ||
PROC_STATUSES = { | ||
|
@@ -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, | ||
cext.SSTOP: _common.STATUS_STOPPED, | ||
cext.SZOMB: _common.STATUS_ZOMBIE, | ||
cext.SDEAD: _common.STATUS_DEAD, | ||
} | ||
|
||
TCP_STATUSES = { | ||
cext.TCPS_ESTABLISHED: _common.CONN_ESTABLISHED, | ||
|
@@ -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 | ||
|
@@ -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(): | ||
|
@@ -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: | ||
|
@@ -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: | ||
|
@@ -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) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved down, after the |
||
families, types = conn_tmap[kind] | ||
rawlist = cext.proc_connections(self.pid, families, types) | ||
ret = [] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?