summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-11-12 02:22:50 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2015-11-12 02:22:50 +0100
commit2c83fa84073fca317c269a764eada7446e7632cf (patch)
tree3b6787c138e086483db7655a6564afa431ffb8c1
parent0ebe433d93bb55674b44d4e4874d5cd793c93bc2 (diff)
downloadpsutil-2c83fa84073fca317c269a764eada7446e7632cf.tar.gz
move psutil_kinfo_proc + add header file
-rw-r--r--psutil/_psutil_openbsd.c24
-rw-r--r--psutil/arch/openbsd/openbsd.c30
-rw-r--r--psutil/arch/openbsd/openbsd.h18
3 files changed, 53 insertions, 19 deletions
diff --git a/psutil/_psutil_openbsd.c b/psutil/_psutil_openbsd.c
index 87fb33cb..ae25e99e 100644
--- a/psutil/_psutil_openbsd.c
+++ b/psutil/_psutil_openbsd.c
@@ -106,37 +106,22 @@
#endif
+#ifdef __FreeBSD__
/*
* Utility function which fills a kinfo_proc struct based on process pid
*/
static int
psutil_kinfo_proc(const pid_t pid, struct kinfo_proc *proc) {
- int ret;
- size_t size = sizeof(struct kinfo_proc);
-
-#ifdef __FreeBSD__
int mib[4];
+ size_t size;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = pid;
- ret = sysctl((int*)mib, 4, proc, &size, NULL, 0);
-#endif
-
-#ifdef __OpenBSD__
- int mib[6];
- mib[0] = CTL_KERN;
- mib[1] = KERN_PROC;
- mib[2] = KERN_PROC_PID;
- mib[3] = pid;
- mib[4] = size;
- mib[5] = 1;
-
- ret = sysctl((int*)mib, 6, proc, &size, NULL, 0);
-#endif
+ size = sizeof(struct kinfo_proc);
- if (ret == -1) {
+ if (sysctl((int *)mib, 4, proc, &size, NULL, 0) == -1) {
PyErr_SetFromErrno(PyExc_OSError);
return -1;
}
@@ -148,6 +133,7 @@ psutil_kinfo_proc(const pid_t pid, struct kinfo_proc *proc) {
}
return 0;
}
+#endif
/*
diff --git a/psutil/arch/openbsd/openbsd.c b/psutil/arch/openbsd/openbsd.c
index fa63ba12..63249ea4 100644
--- a/psutil/arch/openbsd/openbsd.c
+++ b/psutil/arch/openbsd/openbsd.c
@@ -26,6 +26,36 @@
/*
+ * Utility function which fills a kinfo_proc struct based on process pid
+ */
+int
+psutil_kinfo_proc(pid_t pid, struct kinfo_proc *proc) {
+ int ret;
+ int mib[6];
+ size_t size = sizeof(struct kinfo_proc);
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PID;
+ mib[3] = pid;
+ mib[4] = size;
+ mib[5] = 1;
+
+ ret = sysctl((int*)mib, 6, proc, &size, NULL, 0);
+ if (ret == -1) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return -1;
+ }
+ // sysctl stores 0 in the size if we can't find the process information.
+ if (size == 0) {
+ NoSuchProcess();
+ return -1;
+ }
+ return 0;
+}
+
+
+/*
* mimic's FreeBSD kinfo_file call, taking a pid and a ptr to an int as arg
* and returns an array with cnt struct kinfo_file
*/
diff --git a/psutil/arch/openbsd/openbsd.h b/psutil/arch/openbsd/openbsd.h
new file mode 100644
index 00000000..96654934
--- /dev/null
+++ b/psutil/arch/openbsd/openbsd.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2009, Giampaolo Rodola', Landry Breuil.
+ * All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <Python.h>
+
+typedef struct kinfo_proc kinfo_proc;
+
+int psutil_kinfo_proc(pid_t pid, struct kinfo_proc *proc);
+struct kinfo_file * psutil_kinfo_getfile(long pid, int* cnt);
+int psutil_get_proc_list(struct kinfo_proc **procList, size_t *procCount);
+char **_psutil_get_argv(long pid);
+PyObject * psutil_get_cmdline(long pid);
+int psutil_pid_exists(long pid);
+int psutil_raise_ad_or_nsp(long pid);