978381c7b1
* sync configure.ac patch * dbus-spawn: set SIGPIPE to SIG_IGN before activating services * dbus-sysdeps-pthread.c: don't fail if !HAVE_MONOTONIC_CLOCK under -Werror=unused * Remove redundant close() calls * Don't leak temporary fds pointing to /dev/null
91 lines
2.2 KiB
Plaintext
91 lines
2.2 KiB
Plaintext
$OpenBSD: patch-dbus_dbus-sysdeps-util-unix_c,v 1.7 2013/01/08 09:30:27 ajacoutot Exp $
|
|
|
|
XXX push upstream
|
|
|
|
From 9a9b0e2736378d1a8961fb264d7314e921231e8e Mon Sep 17 00:00:00 2001
|
|
From: Michel HERMIER <hermier@frugalware.org>
|
|
Date: Fri, 09 Nov 2012 15:44:43 +0000
|
|
Subject: Don't leak temporary fds pointing to /dev/null
|
|
|
|
--- dbus/dbus-sysdeps-util-unix.c.orig Fri Sep 28 21:17:25 2012
|
|
+++ dbus/dbus-sysdeps-util-unix.c Tue Jan 8 09:59:46 2013
|
|
@@ -55,6 +55,13 @@
|
|
#include <sys/syslimits.h>
|
|
#endif
|
|
|
|
+#ifdef __OpenBSD__
|
|
+#include <sys/param.h>
|
|
+#include <sys/proc.h>
|
|
+#include <sys/sysctl.h>
|
|
+#include <kvm.h>
|
|
+#endif
|
|
+
|
|
#ifndef O_BINARY
|
|
#define O_BINARY 0
|
|
#endif
|
|
@@ -123,6 +130,7 @@ _dbus_become_daemon (const DBusString *pidfile,
|
|
dup2 (dev_null_fd, 2);
|
|
else
|
|
_dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
|
|
+ close (dev_null_fd);
|
|
}
|
|
|
|
if (!keep_umask)
|
|
@@ -1107,7 +1115,14 @@ _dbus_command_for_pid (unsigned long pid,
|
|
/* This is all Linux-specific for now */
|
|
DBusString path;
|
|
DBusString cmdline;
|
|
+#ifndef __OpenBSD__
|
|
int fd;
|
|
+#else
|
|
+ int nproc;
|
|
+ struct kinfo_proc *kp;
|
|
+ kvm_t *kd;
|
|
+ char **argv;
|
|
+#endif
|
|
|
|
if (!_dbus_string_init (&path))
|
|
{
|
|
@@ -1122,6 +1137,7 @@ _dbus_command_for_pid (unsigned long pid,
|
|
return FALSE;
|
|
}
|
|
|
|
+#ifndef __OpenBSD__
|
|
if (!_dbus_string_append_printf (&path, "/proc/%ld/cmdline", pid))
|
|
goto oom;
|
|
|
|
@@ -1148,6 +1164,24 @@ _dbus_command_for_pid (unsigned long pid,
|
|
|
|
if (!_dbus_close (fd, error))
|
|
goto fail;
|
|
+#else
|
|
+ if ((kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL)) == NULL)
|
|
+ goto fail;
|
|
+
|
|
+ if ((kp = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(*kp), &nproc)) == NULL)
|
|
+ goto fail;
|
|
+
|
|
+ if ((kp->p_flag & P_SYSTEM) != 0)
|
|
+ goto fail;
|
|
+
|
|
+ if ((argv = kvm_getargv(kd, kp, 0)) == NULL)
|
|
+ goto fail;
|
|
+
|
|
+ if (!_dbus_string_append_printf (&cmdline, *argv))
|
|
+ goto fail;
|
|
+ else
|
|
+ kvm_close(kd);
|
|
+#endif
|
|
|
|
string_squash_nonprintable (&cmdline);
|
|
|
|
@@ -1162,5 +1196,8 @@ oom:
|
|
fail:
|
|
_dbus_string_free (&cmdline);
|
|
_dbus_string_free (&path);
|
|
+#ifdef __OpenBSD__
|
|
+ kvm_close(kd);
|
|
+#endif
|
|
return FALSE;
|
|
}
|