From 2a8fc4a1ff7cb5040297aba32a7e2b4b6c801174 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 5 Jun 2013 19:58:33 +0100 Subject: [PATCH 2/2] dbus-run-session: remove various extra variables from the environment DBUS_SESSION_BUS_PID is not mandatory to set, but we should unset it if present, since it points to a different session's bus. Likewise for DBUS_SESSION_BUS_WINDOWID. Similarly, if DBUS_STARTER_BUS_TYPE and DBUS_STARTER_ADDRESS are set (as they would be under GNOME Terminal 3.8, see ) then they are likely to point to a different session's bus. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39196 Signed-off-by: Simon McVittie --- doc/dbus-run-session.1.xml.in | 7 +++++++ tools/Makefile.am | 4 ++++ tools/dbus-run-session.c | 30 ++++++++---------------------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/doc/dbus-run-session.1.xml.in b/doc/dbus-run-session.1.xml.in index 693c5e4..5181a8b 100644 --- a/doc/dbus-run-session.1.xml.in +++ b/doc/dbus-run-session.1.xml.in @@ -130,6 +130,13 @@ contain a PROGRAM in the environment variable DBUS_SESSION_BUS_ADDRESS. + +The variables + DBUS_SESSION_BUS_PID, + DBUS_SESSION_BUS_WINDOWID, + DBUS_STARTER_BUS_TYPE and + DBUS_STARTER_ADDRESS + are removed from the environment, if present. BUGS diff --git a/tools/Makefile.am b/tools/Makefile.am index 464a805..73d95fc 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -47,6 +47,10 @@ dbus_launch_SOURCES= \ dbus_run_session_SOURCES = \ dbus-run-session.c + +dbus_run_session_LDADD = \ + $(top_builddir)/dbus/libdbus-1.la \ + $(NULL) endif dbus_cleanup_sockets_SOURCES= \ diff --git a/tools/dbus-run-session.c b/tools/dbus-run-session.c index 4f0b32b..314313d 100644 --- a/tools/dbus-run-session.c +++ b/tools/dbus-run-session.c @@ -35,6 +35,8 @@ #include #include +#include "dbus/dbus.h" + #define MAX_ADDR_LEN 512 #define PIPE_READ_END 0 #define PIPE_WRITE_END 1 @@ -99,22 +101,6 @@ oom (void) exit (1); } -static void * -xmalloc (size_t bytes) -{ - void *ret; - - if (bytes == 0) - bytes = 1; - - ret = malloc (bytes); - - if (ret == NULL) - oom (); - - return ret; -} - typedef enum { READ_STATUS_OK, /**< Read succeeded */ @@ -227,7 +213,6 @@ main (int argc, char **argv) int requires_arg = 0; pid_t bus_pid; pid_t app_pid; - char *envvar; while (i < argc) { @@ -396,11 +381,12 @@ main (int argc, char **argv) close (bus_address_pipe[PIPE_READ_END]); - envvar = xmalloc (strlen ("DBUS_SESSION_BUS_ADDRESS=") + - strlen (bus_address) + 1); - strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS="); - strcat (envvar, bus_address); - putenv (envvar); + if (!dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", bus_address) || + !dbus_setenv ("DBUS_SESSION_BUS_PID", NULL) || + !dbus_setenv ("DBUS_SESSION_BUS_WINDOWID", NULL) || + !dbus_setenv ("DBUS_STARTER_ADDRESS", NULL) || + !dbus_setenv ("DBUS_STARTER_BUS_TYPE", NULL)) + oom (); app_pid = fork (); -- 1.7.10.4