$OpenBSD: patch-src_polkit_polkitunixprocess_c,v 1.6 2014/03/09 22:26:56 ajacoutot Exp $

https://bugs.freedesktop.org/show_bug.cgi?id=75187

--- src/polkit/polkitunixprocess.c.orig	Mon May  6 19:54:15 2013
+++ src/polkit/polkitunixprocess.c	Wed Feb 19 08:50:41 2014
@@ -29,6 +29,10 @@
 #include <sys/sysctl.h>
 #include <sys/user.h>
 #endif
+#ifdef HAVE_OPENBSD
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -86,7 +90,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 +558,38 @@ 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) {
+		perror("sysctl kern.proc.pid");
+		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 +677,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 +696,7 @@ _polkit_unix_process_get_owner (PolkitUnixProcess  *pr
   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 +710,7 @@ _polkit_unix_process_get_owner (PolkitUnixProcess  *pr
   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,7 +722,11 @@ _polkit_unix_process_get_owner (PolkitUnixProcess  *pr
       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
