From: Simon McVittie Date: Wed, 5 Jun 2013 18:58:33 +0000 (+0100) Subject: dbus-run-session: remove various extra variables from the environment X-Git-Tag: dbus-1.7.6~91 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5ee72fe2e1e8fbb7ae09174e8df3ca28228ddd9b;p=thirdparty%2Fdbus.git 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 Reviewed-by: Colin Walters --- diff --git a/doc/dbus-run-session.1.xml.in b/doc/dbus-run-session.1.xml.in index 693c5e4e8..5181a8b1a 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 464a8050f..73d95fcfc 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 4f7243f71..105ab3b4f 100644 --- a/tools/dbus-run-session.c +++ b/tools/dbus-run-session.c @@ -36,6 +36,8 @@ #include #include +#include "dbus/dbus.h" + #define MAX_ADDR_LEN 512 #define PIPE_READ_END 0 #define PIPE_WRITE_END 1 @@ -100,22 +102,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 */ @@ -228,7 +214,6 @@ main (int argc, char **argv) int requires_arg = 0; pid_t bus_pid; pid_t app_pid; - char *envvar; while (i < argc) { @@ -397,11 +382,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 ();