openbsd-ports/x11/gtk+2/patches/patch-gtk_gtkmountoperation-x11_c
2013-01-05 18:13:56 +00:00

117 lines
2.7 KiB
Plaintext

$OpenBSD: patch-gtk_gtkmountoperation-x11_c,v 1.1 2013/01/05 18:13:56 ajacoutot Exp $
From ad9da2727d3e3243fd052c9feb0c55645e87d384 Mon Sep 17 00:00:00 2001
From: Jonathan Matthew <jmatthew@openbsd.org>
Date: Fri, 08 Jul 2011 00:24:32 +0000
Subject: GMountOperation::show-processes support for OpenBSD using kvm(3)
--- gtk/gtkmountoperation-x11.c.orig Tue Nov 8 18:31:30 2011
+++ gtk/gtkmountoperation-x11.c Sat Jan 5 19:08:34 2013
@@ -43,8 +43,8 @@
#include <errno.h>
#if defined(__OpenBSD__)
+#include <stdlib.h>
#include <sys/param.h>
-#include <kvm.h>
#include <fcntl.h>
#include <sys/sysctl.h>
#endif
@@ -724,6 +724,96 @@ pid_get_command_line (GPid pid)
}
/* ---------------------------------------------------------------------------------------------------- */
+
+#elif defined(__OpenBSD__)
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static GPid
+pid_get_parent (GPid pid)
+{
+ struct kinfo_proc kp;
+ size_t len;
+ GPid ppid;
+
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid,
+ sizeof(struct kinfo_proc), 0 };
+
+ if (sysctl(mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
+ return (-1);
+ mib[5] = (len / sizeof(struct kinfo_proc));
+
+ if (sysctl(mib, G_N_ELEMENTS (mib), &kp, &len, NULL, 0) < 0)
+ return -1;
+
+ ppid = kp.p_ppid;
+
+ return ppid;
+}
+
+static gchar *
+pid_get_env (GPid pid, const gchar *key)
+{
+ size_t len = PATH_MAX;
+ char **strs = NULL;
+ char *ret;
+ char *end;
+ int key_len;
+ int i;
+
+ int mib[] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ENV };
+
+ strs = (char **)realloc(strs, len);
+
+ key_len = strlen (key);
+
+ ret = NULL;
+ if (sysctl(mib, G_N_ELEMENTS (mib), strs, &len, NULL, 0) != -1)
+ {
+ for (i = 0; strs[i] != NULL; i++)
+ {
+ if (g_str_has_prefix (strs[i], key) && (*(strs[i] + key_len) == '='))
+ {
+ ret = g_strdup (strs[i] + key_len + 1);
+
+ /* skip invalid UTF-8 */
+ if (!g_utf8_validate (ret, -1, (const gchar **) &end))
+ *end = '\0';
+ break;
+ }
+ }
+ }
+
+ g_free (strs);
+ return ret;
+}
+
+static gchar *
+pid_get_command_line (GPid pid)
+{
+ size_t len = PATH_MAX;
+ char **strs = NULL;
+ char *ret = NULL;
+ char *end;
+
+ int mib[] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ARGV };
+
+ strs = (char **)realloc(strs, len);
+
+ if (sysctl(mib, G_N_ELEMENTS (mib), strs, &len, NULL, 0) == -1) {
+ g_free (strs);
+ return ret;
+ }
+
+ ret = g_strjoinv (" ", strs);
+ /* skip invalid UTF-8 */
+ if (!g_utf8_validate (ret, -1, (const gchar **) &end))
+ *end = '\0';
+
+ g_free (strs);
+ return ret;
+}
+
#else
/* TODO: please implement for your OS - must return valid UTF-8 */