summaryrefslogtreecommitdiff
path: root/src/polkit/polkitunixprocess.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/polkit/polkitunixprocess.c')
-rw-r--r--src/polkit/polkitunixprocess.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/polkit/polkitunixprocess.c b/src/polkit/polkitunixprocess.c
index 9d30cd2..61790b0 100644
--- a/src/polkit/polkitunixprocess.c
+++ b/src/polkit/polkitunixprocess.c
@@ -29,6 +29,9 @@
#include <sys/sysctl.h>
#include <sys/user.h>
#endif
+#ifdef HAVE_OPENBSD
+#include <sys/sysctl.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -86,7 +89,7 @@ static guint64 get_start_time_for_pid (gint pid,
static gint _polkit_unix_process_get_owner (PolkitUnixProcess *process,
GError **error);
-#ifdef HAVE_FREEBSD
+#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD)
static gboolean get_kinfo_proc (gint pid, struct kinfo_proc *p);
#endif
@@ -554,12 +557,36 @@ get_kinfo_proc (pid_t pid, struct kinfo_proc *p)
}
#endif
+#ifdef HAVE_OPENBSD
+static gboolean
+get_kinfo_proc (gint pid, struct kinfo_proc *p)
+{
+ int name[6];
+ u_int namelen;
+ size_t sz;
+
+ sz = sizeof(*p);
+ namelen = 0;
+ name[namelen++] = CTL_KERN;
+ name[namelen++] = KERN_PROC;
+ name[namelen++] = KERN_PROC_PID;
+ name[namelen++] = pid;
+ name[namelen++] = sz;
+ name[namelen++] = 1;
+
+ if (sysctl (name, namelen, p, &sz, NULL, 0) == -1)
+ return FALSE;
+
+ return TRUE;
+}
+#endif
+
static guint64
get_start_time_for_pid (pid_t pid,
GError **error)
{
guint64 start_time;
-#ifndef HAVE_FREEBSD
+#if !defined(HAVE_FREEBSD) && !defined(HAVE_OPENBSD)
gchar *filename;
gchar *contents;
size_t length;
@@ -647,7 +674,11 @@ get_start_time_for_pid (pid_t pid,
goto out;
}
+#ifdef HAVE_FREEBSD
start_time = (guint64) p.ki_start.tv_sec;
+#else
+ start_time = (guint64) p.p_ustart_sec;
+#endif
out:
#endif
@@ -662,7 +693,7 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process,
gint result;
gchar *contents;
gchar **lines;
-#ifdef HAVE_FREEBSD
+#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD)
struct kinfo_proc p;
#else
gchar filename[64];
@@ -676,7 +707,7 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process,
lines = NULL;
contents = NULL;
-#ifdef HAVE_FREEBSD
+#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD)
if (get_kinfo_proc (process->pid, &p) == 0)
{
g_set_error (error,
@@ -688,8 +719,12 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process,
goto out;
}
+#if defined(HAVE_FREEBSD)
result = p.ki_uid;
#else
+ result = p.p_uid;
+#endif
+#else
/* see 'man proc' for layout of the status file
*