+static void
+do_close_stderr (void)
+{
+ int fd;
+
+ fflush (stderr);
+
+ /* dbus-launch is a Unix-only program, so we can rely on /dev/null being there.
+ * We're including unistd.h and we're dealing with sh/csh launch sequences...
+ */
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == -1)
+ {
+ fprintf (stderr, "Internal error: cannot open /dev/null: %s", strerror (errno));
+ exit (1);
+ }
+
+ close (2);
+ if (dup2 (fd, 2) == -1)
+ {
+ /* error; we can't report an error anymore... */
+ exit (1);
+ }
+ close (fd);
+}
+
+static void
+pass_info (const char *runprog, const char *bus_address, pid_t bus_pid,
+ long bus_wid, int c_shell_syntax, int bourne_shell_syntax,
+ int binary_syntax,
+ int argc, char **argv, int remaining_args)
+{
+ if (runprog)
+ {
+ char *envvar;
+ char **args;
+ int i;
+
+ envvar = malloc (strlen ("DBUS_SESSION_BUS_ADDRESS=") +
+ strlen (bus_address) + 1);
+ args = malloc (sizeof (char *) * ((argc-remaining_args)+2));
+
+ if (envvar == NULL || args == NULL)
+ goto oom;
+
+ args[0] = xstrdup (runprog);
+ if (!args[0])
+ goto oom;
+ for (i = 1; i <= (argc-remaining_args); i++)
+ {
+ size_t len = strlen (argv[remaining_args+i-1])+1;
+ args[i] = malloc (len);
+ if (!args[i])
+ goto oom;
+ strncpy (args[i], argv[remaining_args+i-1], len);
+ }
+ args[i] = NULL;
+
+ strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS=");
+ strcat (envvar, bus_address);
+ putenv (envvar);
+
+ execvp (runprog, args);
+ fprintf (stderr, "Couldn't exec %s: %s\n", runprog, strerror (errno));
+ exit (1);
+ }
+ else
+ {
+ print_variables (bus_address, bus_pid, bus_wid, c_shell_syntax,
+ bourne_shell_syntax, binary_syntax);
+ }
+ verbose ("dbus-launch exiting\n");
+
+ fflush (stdout);
+ fflush (stderr);
+ close (1);
+ close (2);
+ exit (0);
+oom:
+ fprintf (stderr, "Out of memory!");
+ exit (1);
+}
+