[tracker] tracker-dbus: add support for OpenBSD



commit 67ccf1dbda724991d1bf1e30be38b388798f3e6a
Author: Antoine Jacoutot <ajacoutot gnome org>
Date:   Thu Apr 18 14:21:49 2013 +0200

    tracker-dbus: add support for OpenBSD
    
    Add OS dependant glue for tracker-dbus on OpenBSD using kvm(3).

 configure.ac                         |    6 +++++
 src/libtracker-common/tracker-dbus.c |   39 ++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index e437183..d1db85b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -231,6 +231,12 @@ LIBTRACKER_COMMON_REQUIRED="glib-2.0     >= $GLIB_REQUIRED
 
 PKG_CHECK_MODULES(LIBTRACKER_COMMON, [$LIBTRACKER_COMMON_REQUIRED])
 
+case $host in
+  *-*-openbsd*)
+    LIBTRACKER_COMMON_LIBS="$LIBTRACKER_COMMON_LIBS -lkvm"
+    ;;
+esac
+
 # Check requirements for libtracker-data
 LIBTRACKER_DATA_REQUIRED="glib-2.0     >= $GLIB_REQUIRED
                           gio-unix-2.0 >= $GLIB_REQUIRED
diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index 09126a2..c086f83 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -23,6 +23,14 @@
 #include <gio/gunixinputstream.h>
 #include <gio/gunixoutputstream.h>
 
+#ifdef __OpenBSD__
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/sysctl.h>
+#include <fcntl.h>
+#include <kvm.h>
+#endif
+
 #include "tracker-dbus.h"
 #include "tracker-log.h"
 
@@ -139,6 +147,7 @@ client_data_new (gchar *sender)
        }
 
        if (get_binary) {
+#ifndef __OpenBSD__
                gchar *filename;
                gchar *pid_str;
                gchar *contents = NULL;
@@ -171,6 +180,36 @@ client_data_new (gchar *sender)
 
                g_strfreev (strv);
                g_free (contents);
+#else
+               gint nproc;
+               struct kinfo_proc *kp;
+               kvm_t *kd;
+               gchar **strv;
+
+               if ((kd = kvm_openfiles (NULL, NULL, NULL, KVM_NO_FILES, NULL)) == NULL)
+                       return cd;
+
+               if ((kp = kvm_getprocs (kd, KERN_PROC_PID, cd->pid, sizeof (*kp), &nproc)) == NULL) {
+                       g_warning ("Could not get process name: %s", kvm_geterr (kd));
+                       kvm_close(kd);
+                       return cd;
+               }
+
+               if ((kp->p_flag & P_SYSTEM) != 0) {
+                       kvm_close(kd);
+                       return cd;
+               }
+
+               strv = kvm_getargv (kd, kp, 0);
+
+               if (strv == NULL) {
+                       kvm_close(kd);
+                       return cd;
+               } else {
+                       cd->binary = g_path_get_basename (strv[0]);
+                       kvm_close(kd);
+               }
+#endif
        }
 
        return cd;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]