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

Landryb openbsd #709

Merged
merged 79 commits into from Nov 12, 2015
Merged
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
0e63add
Build changes to try to support OpenBSD. Two new C files copied from …
landryb Dec 26, 2014
c217d34
First stab at merging patches from wip port against 0.4.1
landryb Dec 26, 2014
1aca8dc
It builds!
landryb Dec 26, 2014
0470086
Make this actuall build
landryb Dec 26, 2014
e1e0ef9
PAGESIZE should be 1 on OpenBSD, DEV_BSIZE is used in _psutil_openbsd.c
landryb Dec 28, 2014
51c48a6
Fix warn() invocations
landryb Dec 28, 2014
3b5edef
use the proper type in Py_BuildValue to return an unsigned long
landryb Dec 28, 2014
c6b4cfb
Add a kinfo_getfile() function mimic'ing what FreeBSD's one does in l…
landryb Dec 28, 2014
1174a60
Implement psutil_per_cpu_times()
landryb Dec 28, 2014
3bfd846
Remove unused utmpx code, is only for FreeBSD >= 9
landryb Dec 28, 2014
4858433
Return an empty string for psutil_proc_cwd() - there's no way to get …
landryb Dec 28, 2014
07b6d65
Proper implementation for psutil_proc_open_files(), returning empty p…
landryb Dec 28, 2014
eca6032
enable per_cpu_times method
landryb Dec 28, 2014
eef37e5
Implement psutil_disk_io_counters()
landryb Dec 28, 2014
6c97eab
remove #if 0 proc_exe implem, wont happen. return process name instead
landryb Dec 28, 2014
a0a3538
remove psutil_cpu_count_phys, wont be implemented
landryb Dec 28, 2014
ecf7f41
add function to get a string from an addru
landryb Dec 28, 2014
63d6dc5
Wip on psutil_proc_connections, lightly tested but seem to do the job
landryb Dec 28, 2014
b960e1a
return the same value for count_logical and count_physical on OpenBSD
landryb Dec 28, 2014
d545b81
Merge remote-tracking branch 'upstream/master' into openbsd
landryb Apr 5, 2015
3c5f259
need netdb.h on OpenBSD too for NI_* defines
landryb Apr 5, 2015
a606d7f
follow changes from #578
landryb Apr 5, 2015
93c5e92
treat OpenBSD as a BSD platform for tests
landryb Apr 5, 2015
e8954bd
more changes from #578
landryb Apr 5, 2015
d478f9b
OpenBSD has AF_LINK too
landryb Apr 5, 2015
3432cee
Fix after changes from #564
landryb Apr 5, 2015
54fa691
use the correct type for cptime2
landryb Apr 5, 2015
ccb461f
BSD-specific tests are in fact FreeBSD only
landryb Apr 7, 2015
5fd6a2a
Revert "BSD-specific tests are in fact FreeBSD only"
landryb Apr 7, 2015
e6febc6
alias SONPROC (process currently on processor) as SRUN
landryb Apr 7, 2015
5ce8351
actually return argv when sysctl call succeeds
landryb Apr 7, 2015
541f4ba
import sys to get uname
landryb Apr 7, 2015
b70a2cb
fix overflow in swap size calculation on 32-bits
landryb Apr 7, 2015
7edb559
enable net_if_stats implem on OpenBSD too, examples/ifconfig.py works
landryb Apr 7, 2015
1da9d09
merge with latest code
giampaolo Sep 6, 2015
32c3db9
fix some tests
giampaolo Sep 6, 2015
2b16959
make the code more similar to master
giampaolo Sep 6, 2015
c83bca3
Fallback on using which(cmdline()[0]) since exe() does not exist on
giampaolo Sep 6, 2015
4cffa4c
merge from master
giampaolo Nov 6, 2015
1374b42
implement net_connections() by iterating over all processes
giampaolo Nov 6, 2015
0410205
implement process cwd
giampaolo Nov 7, 2015
eeac17f
#615: fix proc memory vms to match ps
giampaolo Nov 7, 2015
3b09bd7
Merge branch 'master' into HEAD
giampaolo Nov 8, 2015
67da39e
#615: implement OpenBSD process threads()
giampaolo Nov 8, 2015
2ce156b
#615: implement OpenBSD process num_threads()
giampaolo Nov 8, 2015
f7e0082
#615: disable cpu_affinity() on OpenBSD 'cause it's not supported
giampaolo Nov 8, 2015
5808a06
615: conn TCP status
giampaolo Nov 8, 2015
7748345
C refactoring
giampaolo Nov 8, 2015
de97900
#615: open_connections() IPv6 addr
giampaolo Nov 8, 2015
4cb3373
Merge branch 'master' into landryb-openbsd
giampaolo Nov 9, 2015
ba5d61d
#615: fix process status()
giampaolo Nov 9, 2015
cc6b10e
make Process.connections() raise NSP
giampaolo Nov 9, 2015
1b7b42b
#615: disable memory_maps on OpenBSD
giampaolo Nov 9, 2015
f5bcc2a
fix failing test
giampaolo Nov 9, 2015
6e170f6
fix pid 0 test
giampaolo Nov 9, 2015
7f4004b
first step to merge OpenBSD and FreeBSD impl into one file
giampaolo Nov 11, 2015
16ad39b
remove unused C functions
giampaolo Nov 12, 2015
e702926
move C files around
giampaolo Nov 12, 2015
66a7b56
rename C fun
giampaolo Nov 12, 2015
e81c5e9
check Py* functions ret value
giampaolo Nov 12, 2015
0ebe433
fix compiler warnings
giampaolo Nov 12, 2015
2c83fa8
move psutil_kinfo_proc + add header file
giampaolo Nov 12, 2015
95a5f29
some styling
giampaolo Nov 12, 2015
706c0b6
move poc thread in openbsd.c
giampaolo Nov 12, 2015
74a8bfd
move virtual_mem C fun
giampaolo Nov 12, 2015
be551ba
move swap_mem fun
giampaolo Nov 12, 2015
f5fd52c
rename psutil_kinfo_getfile -> kinfo_getfile
giampaolo Nov 12, 2015
26e1ba1
move openbsd specific modules again
giampaolo Nov 12, 2015
76e23b5
properly redefine proc_open_files
giampaolo Nov 12, 2015
203f776
move proc num fds
giampaolo Nov 12, 2015
1fb02fc
move process cwd
giampaolo Nov 12, 2015
c29ca33
move proc connections
giampaolo Nov 12, 2015
abf77b0
make the code more similar to mastger
giampaolo Nov 12, 2015
f02845d
move per cpu times
giampaolo Nov 12, 2015
bf58200
make code more similar to original bsd
giampaolo Nov 12, 2015
a224ee9
merge disk_partitions stuff
giampaolo Nov 12, 2015
70bf8af
move disk io stuff
giampaolo Nov 12, 2015
995d5ca
more freebsd stuff back
giampaolo Nov 12, 2015
d4becc3
last fixes
giampaolo Nov 12, 2015
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

2 TODO
@@ -35,6 +35,8 @@ HIGHER PRIORITY

* Process.threads(): thread names; patch for OSX available at:
https://code.google.com/p/plcrashreporter/issues/detail?id=65
Sample code:
https://github.com/janmojzis/pstree/blob/master/proc_kvm.c

* Asynchronous psutil.Popen (see http://bugs.python.org/issue1191964)

@@ -892,7 +892,8 @@ Process class
.. method:: threads()

Return threads opened by process as a list of namedtuples including thread
id and thread CPU times (user/system).
id and thread CPU times (user/system). On OpenBSD this method requires
root access.

.. method:: cpu_times()

@@ -959,7 +960,7 @@ Process class
>>> p.cpu_affinity(all_cpus)
>>>
Availability: Linux, Windows, BSD
Availability: Linux, Windows, FreeBSD

.. versionchanged:: 2.2.0 added support for FreeBSD

@@ -1042,6 +1043,8 @@ Process class
...]
>>>
Availability: All platforms except OpenBSD.

.. method:: children(recursive=False)

Return the children of this process as a list of :Class:`Process` objects,
@@ -122,7 +122,7 @@
elif sys.platform.startswith("darwin"):
from . import _psosx as _psplatform

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

elif sys.platform.startswith("sunos"):
@@ -167,6 +167,7 @@
_TOTAL_PHYMEM = None
_POSIX = os.name == 'posix'
_WINDOWS = os.name == 'nt'
_OPENBSD = sys.platform.startswith("openbsd")
_timer = getattr(time, 'monotonic', time.time)


@@ -715,7 +716,7 @@ def rlimit(self, resource, limits=None):
else:
return self._proc.rlimit(resource, limits)

# Windows, Linux and BSD only
# Windows, Linux and FreeBSD only
if hasattr(_psplatform.Process, "cpu_affinity_get"):

def cpu_affinity(self, cpus=None):
@@ -754,6 +755,7 @@ def threads(self):
"""Return threads opened by process as a list of
(id, user_time, system_time) namedtuples representing
thread id and thread CPU times (user/system).
On OpenBSD this method requires root access.
"""
return self._proc.threads()

@@ -961,32 +963,33 @@ def memory_percent(self):
except ZeroDivisionError:
return 0.0

def memory_maps(self, grouped=True):
"""Return process' mapped memory regions as a list of namedtuples
whose fields are variable depending on the platform.
if not _OPENBSD:
def memory_maps(self, grouped=True):
"""Return process' mapped memory regions as a list of namedtuples
whose fields are variable depending on the platform.
If 'grouped' is True the mapped regions with the same 'path'
are grouped together and the different memory fields are summed.
If 'grouped' is True the mapped regions with the same 'path'
are grouped together and the different memory fields are summed.
If 'grouped' is False every mapped region is shown as a single
entity and the namedtuple will also include the mapped region's
address space ('addr') and permission set ('perms').
"""
it = self._proc.memory_maps()
if grouped:
d = {}
for tupl in it:
path = tupl[2]
nums = tupl[3:]
try:
d[path] = map(lambda x, y: x + y, d[path], nums)
except KeyError:
d[path] = nums
nt = _psplatform.pmmap_grouped
return [nt(path, *d[path]) for path in d] # NOQA
else:
nt = _psplatform.pmmap_ext
return [nt(*x) for x in it]
If 'grouped' is False every mapped region is shown as a single
entity and the namedtuple will also include the mapped region's
address space ('addr') and permission set ('perms').
"""
it = self._proc.memory_maps()
if grouped:
d = {}
for tupl in it:
path = tupl[2]
nums = tupl[3:]
try:
d[path] = map(lambda x, y: x + y, d[path], nums)
except KeyError:
d[path] = nums
nt = _psplatform.pmmap_grouped
return [nt(path, *d[path]) for path in d] # NOQA
else:
nt = _psplatform.pmmap_ext
return [nt(*x) for x in it]

def open_files(self):
"""Return files opened by process as a list of
@@ -1028,8 +1031,13 @@ def _send_signal(self, sig):
os.kill(self.pid, sig)
except OSError as err:
if err.errno == errno.ESRCH:
self._gone = True
raise NoSuchProcess(self.pid, self._name)
if _OPENBSD and pid_exists(self.pid):
# We do this because os.kill() lies in case of
# zombie processes.
raise ZombieProcess(self.pid, self._name, self._ppid)
else:
self._gone = True
raise NoSuchProcess(self.pid, self._name)
if err.errno in (errno.EPERM, errno.EACCES):
raise AccessDenied(self.pid, self._name)
raise
@@ -6,6 +6,7 @@

import collections
import functools
import os
import sys

__all__ = ["PY3", "long", "xrange", "unicode", "callable", "lru_cache"]
@@ -191,3 +192,55 @@ def cache_clear():
return functools.update_wrapper(wrapper, user_function)

return decorating_function


# python 3.3
try:
from shutil import which
except ImportError:
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
"""Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
file.
`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
of os.environ.get("PATH"), or can be overridden with a custom search
path.
"""
def _access_check(fn, mode):
return (os.path.exists(fn) and os.access(fn, mode)
and not os.path.isdir(fn))

if os.path.dirname(cmd):
if _access_check(cmd, mode):
return cmd
return None

if path is None:
path = os.environ.get("PATH", os.defpath)
if not path:
return None
path = path.split(os.pathsep)

if sys.platform == "win32":
if os.curdir not in path:
path.insert(0, os.curdir)

pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
files = [cmd]
else:
files = [cmd + ext for ext in pathext]
else:
files = [cmd]

seen = set()
for dir in path:
normdir = os.path.normcase(dir)
if normdir not in seen:
seen.add(normdir)
for thefile in files:
name = os.path.join(dir, thefile)
if _access_check(name, mode):
return name
return None
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.