$OpenBSD: patch-src_polkit_polkitunixprocess_c,v 1.9 2015/07/20 20:16:59 ajacoutot Exp $

From 074df27827fd773f1c76545cd08da568440ca41f Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@gnome.org>
Date: Sun, 19 Jul 2015 02:19:08 +0200
Subject: Add support for OpenBSD

--- src/polkit/polkitunixprocess.c.orig	Tue Jan 14 23:42:25 2014
+++ src/polkit/polkitunixprocess.c	Sun Jul 19 02:14:03 2015
@@ -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  *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 +707,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 +719,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
