108 lines
2.6 KiB
Plaintext
108 lines
2.6 KiB
Plaintext
$OpenBSD: patch-src_polkit_polkitunixprocess_c,v 1.3 2011/08/17 16:59:27 ajacoutot Exp $
|
|
--- src/polkit/polkitunixprocess.c.orig Mon Aug 1 15:42:02 2011
|
|
+++ src/polkit/polkitunixprocess.c Wed Aug 17 18:39:34 2011
|
|
@@ -29,6 +29,12 @@
|
|
#include <sys/sysctl.h>
|
|
#include <sys/user.h>
|
|
#endif
|
|
+#ifdef __OpenBSD__
|
|
+#include <kvm.h>
|
|
+#include <stdio.h>
|
|
+#include <sys/param.h>
|
|
+#include <sys/sysctl.h>
|
|
+#endif
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
@@ -86,7 +92,7 @@ static guint64 get_start_time_for_pid (gint pid,
|
|
static gint _polkit_unix_process_get_owner (PolkitUnixProcess *process,
|
|
GError **error);
|
|
|
|
-#ifdef HAVE_FREEBSD
|
|
+#if defined(HAVE_FREEBSD) || defined(__OpenBSD__)
|
|
static gboolean get_kinfo_proc (gint pid, struct kinfo_proc *p);
|
|
#endif
|
|
|
|
@@ -554,12 +560,38 @@ get_kinfo_proc (pid_t pid, struct kinfo_proc *p)
|
|
}
|
|
#endif
|
|
|
|
+#ifdef __OpenBSD__
|
|
+get_kinfo_proc (pid_t pid,
|
|
+ struct kinfo_proc *p)
|
|
+{
|
|
+ int name[6];
|
|
+ u_int namelen;
|
|
+ size_t sz;
|
|
+
|
|
+ sz = sizeof(*p);
|
|
+ namelen = 0;
|
|
+ name[namelen++] = CTL_KERN;
|
|
+ name[namelen++] = KERN_PROC;
|
|
+ name[namelen++] = KERN_PROC_PID;
|
|
+ name[namelen++] = pid;
|
|
+ name[namelen++] = sz;
|
|
+ name[namelen++] = 1;
|
|
+
|
|
+ if (sysctl (name, namelen, p, &sz, NULL, 0) == -1) {
|
|
+ perror("sysctl kern.proc.pid");
|
|
+ return FALSE;
|
|
+ }
|
|
+
|
|
+ return TRUE;
|
|
+}
|
|
+#endif
|
|
+
|
|
static guint64
|
|
get_start_time_for_pid (pid_t pid,
|
|
GError **error)
|
|
{
|
|
guint64 start_time;
|
|
-#ifndef HAVE_FREEBSD
|
|
+#if !defined(HAVE_FREEBSD) && !defined(__OpenBSD__)
|
|
gchar *filename;
|
|
gchar *contents;
|
|
size_t length;
|
|
@@ -647,7 +679,11 @@ get_start_time_for_pid (pid_t pid,
|
|
goto out;
|
|
}
|
|
|
|
+#ifdef HAVE_FREEBSD
|
|
start_time = (guint64) p.ki_start.tv_sec;
|
|
+#else
|
|
+ start_time = (guint64) p.p_ustart_sec;
|
|
+#endif
|
|
|
|
out:
|
|
#endif
|
|
@@ -662,7 +698,7 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *pr
|
|
gint result;
|
|
gchar *contents;
|
|
gchar **lines;
|
|
-#ifdef HAVE_FREEBSD
|
|
+#if defined(HAVE_FREEBSD) || defined(__OpenBSD__)
|
|
struct kinfo_proc p;
|
|
#else
|
|
gchar filename[64];
|
|
@@ -676,7 +712,7 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *pr
|
|
lines = NULL;
|
|
contents = NULL;
|
|
|
|
-#ifdef HAVE_FREEBSD
|
|
+#if defined(HAVE_FREEBSD) || defined(__OpenBSD__)
|
|
if (get_kinfo_proc (process->pid, &p) == 0)
|
|
{
|
|
g_set_error (error,
|
|
@@ -688,7 +724,11 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *pr
|
|
goto out;
|
|
}
|
|
|
|
+#if defined(HAVE_FREEBSD)
|
|
result = p.ki_uid;
|
|
+#else
|
|
+ result = p.p_uid;
|
|
+#endif
|
|
#else
|
|
|
|
/* see 'man proc' for layout of the status file
|