summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-11-12 06:09:28 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2015-11-12 06:09:28 +0100
commitd4becc3f156bdc7565a64061f1c5711eb9f6791a (patch)
tree434f04cbf95c47ecee9c57a8de7c4065bfa8740f
parent995d5ca8ccfa5983749afe4e232414c66afe0141 (diff)
downloadpsutil-landryb-openbsd.tar.gz
last fixeslandryb-openbsd
-rw-r--r--psutil/_psbsd.py5
-rw-r--r--psutil/_psutil_openbsd.c53
2 files changed, 51 insertions, 7 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 8b980b2d..57d847b9 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -111,7 +111,7 @@ def virtual_memory():
def swap_memory():
"""System swap memory as (total, used, free, sin, sout) namedtuple."""
- if sys.platform.startswith("openbsd"):
+ if OPENBSD:
PAGESIZE = 1
total, used, free, sin, sout = [x * PAGESIZE for x in cext.swap_mem()]
percent = usage_percent(used, total, _round=1)
@@ -305,8 +305,7 @@ def wrap_exceptions(fun):
ZombieProcess is None):
raise
if err.errno == errno.ESRCH:
- # if not pid_exists(self.pid):
- if self.pid not in pids():
+ if not pid_exists(self.pid):
raise NoSuchProcess(self.pid, self._name)
else:
raise ZombieProcess(self.pid, self._name, self._ppid)
diff --git a/psutil/_psutil_openbsd.c b/psutil/_psutil_openbsd.c
index 8406d083..9c979306 100644
--- a/psutil/_psutil_openbsd.c
+++ b/psutil/_psutil_openbsd.c
@@ -32,7 +32,6 @@
#include <sys/file.h>
#include <sys/socket.h>
#include <net/route.h>
-
#include <sys/socketvar.h> // for struct xsocket
#include <sys/un.h>
#include <sys/unpcb.h>
@@ -86,8 +85,6 @@
#include <sys/file.h>
#undef _KERNEL
#include <sys/sched.h> // for CPUSTATES & CP_*
- #include <sys/swap.h>
- #include <kvm.h>
#endif
@@ -134,6 +131,24 @@ psutil_kinfo_proc(const pid_t pid, struct kinfo_proc *proc) {
#endif
+#ifdef __FreeBSD__
+/*
+ * Set exception to AccessDenied if pid exists else NoSuchProcess.
+ */
+void
+psutil_raise_ad_or_nsp(long pid) {
+ int ret;
+ ret = psutil_pid_exists(pid);
+ if (ret == 0)
+ NoSuchProcess();
+ else if (ret == 1)
+ AccessDenied();
+ else
+ return NULL;
+}
+#endif
+
+
/*
* Return a Python list of all the PIDs running on the system.
*/
@@ -641,10 +656,13 @@ psutil_proc_io_counters(PyObject *self, PyObject *args) {
}
+#ifdef __OpenBSD__
+#define ptoa(x) ((paddr_t)(x) << PAGE_SHIFT)
+#endif
+
/*
* Return extended memory info for a process as a Python tuple.
*/
-#define ptoa(x) ((paddr_t)(x) << PAGE_SHIFT)
static PyObject *
psutil_proc_memory_info(PyObject *self, PyObject *args) {
long pid;
@@ -1724,6 +1742,7 @@ psutil_users(PyObject *self, PyObject *args) {
if (py_retlist == NULL)
return NULL;
+#if __FreeBSD_version < 900000 || __OpenBSD__
struct utmp ut;
FILE *fp;
@@ -1754,7 +1773,33 @@ psutil_users(PyObject *self, PyObject *args) {
}
fclose(fp);
+#else
+ struct utmpx *utx;
+
+ while ((utx = getutxent()) != NULL) {
+ if (utx->ut_type != USER_PROCESS)
+ continue;
+ py_tuple = Py_BuildValue(
+ "(sssf)",
+ utx->ut_user, // username
+ utx->ut_line, // tty
+ utx->ut_host, // hostname
+ (float)utx->ut_tv.tv_sec // start time
+ );
+
+ if (!py_tuple) {
+ endutxent();
+ goto error;
+ }
+ if (PyList_Append(py_retlist, py_tuple)) {
+ endutxent();
+ goto error;
+ }
+ Py_DECREF(py_tuple);
+ }
+ endutxent();
+#endif
return py_retlist;
error: