$OpenBSD: patch-dbus_dbus-sysdeps-util-unix_c,v 1.8 2013/05/07 07:00:01 ajacoutot Exp $

XXX push upstream

--- dbus/dbus-sysdeps-util-unix.c.orig	Fri Nov  9 17:01:44 2012
+++ dbus/dbus-sysdeps-util-unix.c	Tue May  7 08:47:04 2013
@@ -55,6 +55,13 @@
 #include <sys/syslimits.h>
 #endif
 
+#ifdef __OpenBSD__
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/sysctl.h>
+#include <kvm.h>
+#endif
+
 #ifndef O_BINARY
 #define O_BINARY 0
 #endif
@@ -1108,7 +1115,14 @@ _dbus_command_for_pid (unsigned long  pid,
   /* This is all Linux-specific for now */
   DBusString path;
   DBusString cmdline;
+#ifndef __OpenBSD__
   int fd;
+#else
+  int nproc;
+  struct kinfo_proc *kp;
+  kvm_t *kd;
+  char **argv;
+#endif
   
   if (!_dbus_string_init (&path)) 
     {
@@ -1123,6 +1137,7 @@ _dbus_command_for_pid (unsigned long  pid,
       return FALSE;
     }
   
+#ifndef __OpenBSD__
   if (!_dbus_string_append_printf (&path, "/proc/%ld/cmdline", pid))
     goto oom;
   
@@ -1149,6 +1164,24 @@ _dbus_command_for_pid (unsigned long  pid,
   
   if (!_dbus_close (fd, error))
     goto fail;
+#else
+  if ((kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL)) == NULL)
+    goto fail;
+
+  if ((kp = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(*kp), &nproc)) == NULL)
+    goto fail;
+
+  if ((kp->p_flag & P_SYSTEM) != 0)
+    goto fail;
+
+  if ((argv = kvm_getargv(kd, kp, 0)) == NULL)
+    goto fail;
+
+  if (!_dbus_string_append_printf (&cmdline, *argv))
+    goto fail;
+  else
+    kvm_close(kd);
+#endif
   
   string_squash_nonprintable (&cmdline);  
 
@@ -1163,5 +1196,8 @@ oom:
 fail:
   _dbus_string_free (&cmdline);
   _dbus_string_free (&path);
+#ifdef __OpenBSD__
+  kvm_close(kd);
+#endif
   return FALSE;
 }
