]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-run-session: remove various extra variables from the environment
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 5 Jun 2013 18:58:33 +0000 (19:58 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 23 Aug 2013 10:41:16 +0000 (11:41 +0100)
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
<https://bugs.freedesktop.org/show_bug.cgi?id=63119>) 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 <simon.mcvittie@collabora.co.uk>
Reviewed-by: Colin Walters <walters@verbum.org>
doc/dbus-run-session.1.xml.in
tools/Makefile.am
tools/dbus-run-session.c

index 693c5e4e85728a72bd3c8bde7e1353dd810cfab9..5181a8b1acb7744d02dce1130586ed4b2cc536a7 100644 (file)
@@ -130,6 +130,13 @@ contain a
 <emphasis remap='I'>PROGRAM</emphasis>
 in the environment variable
 <emphasis remap='B'>DBUS_SESSION_BUS_ADDRESS</emphasis>.</para>
+
+<para>The variables
+  <emphasis remap='B'>DBUS_SESSION_BUS_PID</emphasis>,
+  <emphasis remap='B'>DBUS_SESSION_BUS_WINDOWID</emphasis>,
+  <emphasis remap='B'>DBUS_STARTER_BUS_TYPE</emphasis> and
+  <emphasis remap='B'>DBUS_STARTER_ADDRESS</emphasis>
+  are removed from the environment, if present.</para>
 </refsect1>
 
 <refsect1 id='bugs'><title>BUGS</title>
index 464a8050f2bb6be2023373ac28eec99590d1b55a..73d95fcfce3a4adeba9607c750396a5102e55144 100644 (file)
@@ -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=                  \
index 4f7243f71a8ee559edf8ef058f50d41c63ad539d..105ab3b4fef5b983b33abf0c9c671fd8abebbf2d 100644 (file)
@@ -36,6 +36,8 @@
 #include <sys/wait.h>
 #include <signal.h>
 
+#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 ();