[tracker-miners: 1/2] OpenBSD: implement find_command




commit 0914a401f0290f20f8acd03e2b5335fde75119e1
Author: Antoine Jacoutot <ajacoutot openbsd org>
Date:   Sat Mar 5 12:16:29 2022 +0000

    OpenBSD: implement find_command

 src/tracker/tracker-process.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/src/tracker/tracker-process.c b/src/tracker/tracker-process.c
index 40396578b..718d0f9c9 100644
--- a/src/tracker/tracker-process.c
+++ b/src/tracker/tracker-process.c
@@ -27,12 +27,8 @@
 #include <glib/gi18n.h>
 
 #ifdef __OpenBSD__
-#include <sys/param.h>
-#include <sys/proc.h>
+#include <sys/types.h>
 #include <sys/sysctl.h>
-#include <fcntl.h>
-#include <kvm.h>
-#include <unistd.h>
 #endif
 
 #ifdef __sun
@@ -68,6 +64,7 @@ tracker_process_data_free (TrackerProcessData *pd)
 static gchar *
 find_command (pid_t pid)
 {
+#ifndef __OpenBSD__
        gchar *proc_path, path[PATH_MAX + 1];
        ssize_t len;
 
@@ -87,6 +84,34 @@ find_command (pid_t pid)
        }
 
        return g_path_get_basename (path);
+#else /* __OpenBSD__ */
+       g_autofree char *path = NULL;
+       gchar **args = NULL;
+       gint mib[4];
+       size_t len;
+
+       mib[0] = CTL_KERN;
+       mib[1] = KERN_PROC_ARGS;
+       mib[2] = pid;
+       mib[3] = KERN_PROC_ARGV;
+
+       if (sysctl (mib, 4, NULL, &len, NULL, 0) == -1)
+               goto fail;
+
+       args = g_malloc0 (len);
+       if (args == NULL)
+               goto fail;
+
+       if (sysctl (mib, 4, args, &len, NULL, 0) == -1)
+               goto fail;
+
+       path = g_strndup (args[0], PATH_MAX);
+       return g_path_get_basename (path);
+
+fail:
+       g_free (args);
+       return NULL;
+#endif /* !__OpenBSD__ */
 }
 
 static pid_t


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