[tracker] openbsd: implement tracker_process_get_uid_for_pid()



commit 95ddae1b224c75b37b2dbe5f1f6b4cb69ea79bdd
Author: Antoine Jacoutot <ajacoutot gnome org>
Date:   Sat Mar 28 17:56:44 2015 +0100

    openbsd: implement tracker_process_get_uid_for_pid()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697719

 src/tracker/tracker-process.c |   54 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/tracker/tracker-process.c b/src/tracker/tracker-process.c
index 7792730..71800d2 100644
--- a/src/tracker/tracker-process.c
+++ b/src/tracker/tracker-process.c
@@ -26,6 +26,15 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
+#ifdef __OpenBSD__
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/sysctl.h>
+#include <fcntl.h>
+#include <kvm.h>
+#include <unistd.h>
+#endif
+
 #include "tracker-process.h"
 
 static TrackerProcessData *
@@ -134,6 +143,7 @@ tracker_process_get_uid_for_pid (const gchar  *pid_as_string,
 GSList *
 tracker_process_find_all (void)
 {
+#ifndef __OpenBSD__
        GSList *pids, *l;
        GSList *found_pids = NULL;
        guint32 own_pid;
@@ -221,6 +231,50 @@ tracker_process_find_all (void)
        g_slist_free (pids);
 
        return g_slist_reverse (found_pids);
+#else /* ! __OpenBSD__ */
+       GSList *found_pids = NULL;
+       gchar **strv;
+       gchar *basename;
+       pid_t pid;
+       gint i, nproc;
+       gchar buf[_POSIX2_LINE_MAX];
+       struct kinfo_proc *plist, *kp;
+       kvm_t *kd;
+
+       if ((kd = kvm_openfiles (NULL, NULL, NULL, KVM_NO_FILES, buf)) == NULL)
+               return NULL;
+
+       if ((plist = kvm_getprocs (kd, KERN_PROC_ALL, 0, sizeof (*plist), &nproc)) == NULL)
+               return NULL;
+
+       for (i = 0, kp = plist; i < nproc; i++, kp++) {
+               if ((kp->p_flag & P_SYSTEM) != 0)
+                       continue;
+               if ((strv = kvm_getargv (kd, kp, 0)) == NULL)
+                       continue;
+
+               pid = kp->p_pid;
+
+               /* Don't return our own PID */
+               if (pid == getpid ())
+                       continue;
+
+               /* Don't return PID we don't own */
+               if (kp->p_uid != getuid ())
+                       continue;
+
+               basename = g_path_get_basename (strv[0]);
+
+               if ((g_str_has_prefix (basename, "tracker") ||
+                    g_str_has_prefix (basename, "lt-tracker"))) {
+                       found_pids = g_slist_prepend (found_pids, process_data_new (basename, pid));
+               } else {
+                       g_free (basename);
+               }
+       }
+
+       return g_slist_reverse (found_pids);
+#endif
 }
 
 gint


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