[gtk+/font-chooser] GMountOperation::show-processes support for OpenBSD using kvm(3)
- From: Alberto Ruiz <aruiz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/font-chooser] GMountOperation::show-processes support for OpenBSD using kvm(3)
- Date: Wed, 20 Jul 2011 20:14:51 +0000 (UTC)
commit eadf7203c90dd13ebe9937683846cba26795c3a3
Author: Jonathan Matthew <jmatthew openbsd org>
Date: Fri Jul 8 10:24:32 2011 +1000
GMountOperation::show-processes support for OpenBSD using kvm(3)
configure.ac | 7 +++
gtk/gtkmountoperation-x11.c | 100 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4caa7df..d0b173a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -165,6 +165,9 @@ case $host in
*-*-linux*)
os_linux=yes
;;
+ *-*-openbsd*)
+ os_openbsd=yes
+ ;;
esac
dnl
@@ -1300,6 +1303,10 @@ if test "x$enable_x11_backend" = xyes; then
GTK_PACKAGES="$GTK_PACKAGES pangoft2"
fi
GTK_EXTRA_LIBS=
+if test x"$os_openbsd" = xyes; then
+ GTK_EXTRA_LIBS="$GTK_EXTRA_LIBS -lkvm"
+fi
+
GTK_EXTRA_CFLAGS=
GTK_DEP_LIBS="$GDK_EXTRA_LIBS $GTK_DEP_LIBS_FOR_X `$PKG_CONFIG --libs $PANGO_PACKAGES $GTK_PACKAGES_FOR_X $GTK_PACKAGES` $GTK_EXTRA_LIBS"
GTK_DEP_CFLAGS="`$PKG_CONFIG --cflags gthread-2.0 $GDK_PACKAGES $GTK_PACKAGES` $GDK_EXTRA_CFLAGS $GTK_EXTRA_CFLAGS"
diff --git a/gtk/gtkmountoperation-x11.c b/gtk/gtkmountoperation-x11.c
index d757139..1663a02 100644
--- a/gtk/gtkmountoperation-x11.c
+++ b/gtk/gtkmountoperation-x11.c
@@ -42,6 +42,12 @@
#include <signal.h>
#include <errno.h>
+#if defined(__OpenBSD__)
+#include <kvm.h>
+#include <fcntl.h>
+#include <sys/sysctl.h>
+#endif
+
#include "gtkmountoperationprivate.h"
/* ---------------------------------------------------------------------------------------------------- */
@@ -711,6 +717,100 @@ pid_get_command_line (GPid pid)
}
/* ---------------------------------------------------------------------------------------------------- */
+
+#elif defined(__OpenBSD__)
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static GPid
+pid_get_parent (GPid pid)
+{
+ struct kinfo_proc *proc;
+ int count;
+ kvm_t *kvm;
+ GPid ppid = 0;
+
+ kvm = kvm_openfiles (NULL, NULL, NULL, KVM_NO_FILES, NULL);
+ if (kvm == NULL)
+ return 0;
+
+ proc = kvm_getprocs (kvm, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
+ if (count == 1)
+ ppid = proc->p_ppid;
+
+ kvm_close (kvm);
+ return ppid;
+}
+
+static gchar *
+pid_get_env (GPid pid, const gchar *key)
+{
+ kvm_t *kvm;
+ struct kinfo_proc *proc;
+ char **strs;
+ char *ret;
+ char *end;
+ int key_len;
+ int count;
+ int i;
+
+ kvm = kvm_openfiles (NULL, NULL, NULL, KVM_NO_FILES, NULL);
+ if (kvm == NULL)
+ return NULL;
+
+ key_len = strlen (key);
+
+ ret = NULL;
+ proc = kvm_getprocs (kvm, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
+ if (proc != NULL)
+ {
+ strs = kvm_getenvv (kvm, proc, 0);
+ 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;
+ }
+ }
+ }
+
+ kvm_close (kvm);
+ return ret;
+}
+
+static gchar *
+pid_get_command_line (GPid pid)
+{
+ kvm_t *kvm;
+ struct kinfo_proc *proc;
+ int count;
+ char **strs;
+ char *ret;
+ char *end;
+
+ kvm = kvm_openfiles (NULL, NULL, NULL, KVM_NO_FILES, NULL);
+ if (kvm == NULL)
+ return NULL;
+
+ proc = kvm_getprocs (kvm, KERN_PROC_PID, pid, sizeof (struct kinfo_proc), &count);
+ if (proc == NULL)
+ return NULL;
+
+ strs = kvm_getargv (kvm, proc, 0);
+ ret = g_strjoinv (" ", strs);
+ /* skip invalid UTF-8 */
+ if (!g_utf8_validate (ret, -1, (const gchar **) &end))
+ *end = '\0';
+
+ kvm_close (kvm);
+ return ret;
+}
+
#else
/* TODO: please implement for your OS - must return valid UTF-8 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]