2003-10-12 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / tools / dbus-launch.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-launch.c  dbus-launch utility
3  *
4  * Copyright (C) 2003 Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23 #include <config.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <signal.h>
28 #include <sys/wait.h>
29 #include <errno.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <signal.h>
33 #include <stdarg.h>
34 #ifdef DBUS_BUILD_X11
35 #include <X11/Xlib.h>
36 #endif
37
38 #ifndef TRUE
39 #define TRUE (1)
40 #endif
41
42 #ifndef FALSE
43 #define FALSE (0)
44 #endif
45
46 #undef  MAX
47 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
48
49 static void
50 verbose (const char *format,
51          ...)
52 {
53   va_list args;
54   static int verbose = TRUE;
55   static int verbose_initted = FALSE;
56   
57   /* things are written a bit oddly here so that
58    * in the non-verbose case we just have the one
59    * conditional and return immediately.
60    */
61   if (!verbose)
62     return;
63   
64   if (!verbose_initted)
65     {
66       verbose = getenv ("DBUS_VERBOSE") != NULL;
67       verbose_initted = TRUE;
68       if (!verbose)
69         return;
70     }
71
72   fprintf (stderr, "%lu: ", (unsigned long) getpid ());
73   
74   va_start (args, format);
75   vfprintf (stderr, format, args);
76   va_end (args);
77 }
78
79 static void
80 usage (int ecode)
81 {
82   fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax] [--auto-syntax] [--exit-with-session]\n");
83   exit (ecode);
84 }
85
86 static void
87 version (void)
88 {
89   printf ("D-BUS Message Bus Launcher %s\n"
90           "Copyright (C) 2003 Red Hat, Inc.\n"
91           "This is free software; see the source for copying conditions.\n"
92           "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
93           VERSION);
94   exit (0);
95 }
96
97 static char *
98 xstrdup (const char *str)
99 {
100   int len;
101   char *copy;
102   
103   if (str == NULL)
104     return NULL;
105   
106   len = strlen (str);
107
108   copy = malloc (len + 1);
109   if (copy == NULL)
110     return NULL;
111
112   memcpy (copy, str, len + 1);
113   
114   return copy;
115 }
116
117 typedef enum
118 {
119   READ_STATUS_OK,    /**< Read succeeded */
120   READ_STATUS_ERROR, /**< Some kind of error */
121   READ_STATUS_EOF    /**< EOF returned */
122 } ReadStatus;
123
124 static ReadStatus
125 read_line (int        fd,
126            char      *buf,
127            size_t     maxlen)
128 {
129   size_t bytes = 0;
130   ReadStatus retval;
131
132   memset (buf, '\0', maxlen);
133   maxlen -= 1; /* ensure nul term */
134   
135   retval = READ_STATUS_OK;
136   
137   while (TRUE)
138     {
139       size_t chunk;    
140       size_t to_read;
141       
142     again:
143       to_read = maxlen - bytes;
144
145       if (to_read == 0)
146         break;
147       
148       chunk = read (fd,
149                     buf + bytes,
150                     to_read);
151       if (chunk < 0 && errno == EINTR)
152         goto again;
153           
154       if (chunk < 0)
155         {
156           retval = READ_STATUS_ERROR;
157           break;
158         }
159       else if (chunk == 0)
160         {
161           retval = READ_STATUS_EOF;
162           break; /* EOF */
163         }
164       else /* chunk > 0 */
165         bytes += chunk;
166     }
167
168   if (retval == READ_STATUS_EOF &&
169       bytes > 0)
170     retval = READ_STATUS_OK;
171   
172   /* whack newline */
173   if (retval != READ_STATUS_ERROR &&
174       bytes > 0 &&
175       buf[bytes-1] == '\n')
176     buf[bytes-1] = '\0';
177   
178   return retval;
179 }
180
181 static ReadStatus
182 read_pid (int        fd,
183           pid_t     *buf)
184 {
185   size_t bytes = 0;
186   ReadStatus retval;
187
188   retval = READ_STATUS_OK;
189   
190   while (TRUE)
191     {
192       size_t chunk;    
193       size_t to_read;
194       
195     again:
196       to_read = sizeof (pid_t) - bytes;
197
198       if (to_read == 0)
199         break;
200       
201       chunk = read (fd,
202                     ((char*)buf) + bytes,
203                     to_read);
204       if (chunk < 0 && errno == EINTR)
205         goto again;
206           
207       if (chunk < 0)
208         {
209           retval = READ_STATUS_ERROR;
210           break;
211         }
212       else if (chunk == 0)
213         {
214           retval = READ_STATUS_EOF;
215           break; /* EOF */
216         }
217       else /* chunk > 0 */
218         bytes += chunk;
219     }
220
221   return retval;
222 }
223
224 static void
225 do_write (int fd, const void *buf, size_t count)
226 {
227   size_t bytes_written;
228   int ret;
229   
230   bytes_written = 0;
231   
232  again:
233   
234   ret = write (fd, ((const char*)buf) + bytes_written, count - bytes_written);
235
236   if (ret < 0)
237     {
238       if (errno == EINTR)
239         goto again;
240       else
241         {
242           fprintf (stderr, "Failed to write data to pipe!\n");
243           exit (1); /* give up, we suck */
244         }
245     }
246   else
247     bytes_written += ret;
248   
249   if (bytes_written < count)
250     goto again;
251 }
252
253 static void
254 write_pid (int   fd,
255            pid_t pid)
256 {
257   do_write (fd, &pid, sizeof (pid));
258 }
259
260 static int
261 do_waitpid (pid_t pid)
262 {
263   int ret;
264   
265  again:
266   ret = waitpid (pid, NULL, 0);
267
268   if (ret < 0 &&
269       errno == EINTR)
270     goto again;
271
272   return ret;
273 }
274
275 static pid_t bus_pid_to_kill = -1;
276
277 static void
278 kill_bus_and_exit (void)
279 {
280   verbose ("Killing message bus and exiting babysitter\n");
281   
282   /* in case these point to any NFS mounts, get rid of them immediately */
283   close (0);
284   close (1);
285   close (2);
286
287   kill (bus_pid_to_kill, SIGTERM);
288   sleep (3);
289   kill (bus_pid_to_kill, SIGKILL);
290
291   exit (0);
292 }
293
294 #ifdef DBUS_BUILD_X11
295 static int
296 x_io_error_handler (Display *xdisplay)
297 {
298   verbose ("X IO error\n");
299   kill_bus_and_exit ();
300   return 0;
301 }
302 #endif
303
304 static int got_sighup = FALSE;
305
306 static void
307 signal_handler (int sig)
308 {
309   switch (sig)
310     {
311     case SIGHUP:
312       got_sighup = TRUE;
313       break;
314     }
315 }
316
317 static void
318 kill_bus_when_session_ends (void)
319 {
320   int tty_fd;
321   int x_fd;
322   fd_set read_set;
323   fd_set err_set;
324   int ret;
325   struct sigaction act;
326   sigset_t empty_mask;
327 #ifdef DBUS_BUILD_X11
328   Display *xdisplay;
329 #endif
330   
331   /* install SIGHUP handler */
332   got_sighup = FALSE;
333   sigemptyset (&empty_mask);
334   act.sa_handler = signal_handler;
335   act.sa_mask    = empty_mask;
336   act.sa_flags   = 0;
337   sigaction (SIGHUP,  &act, 0);
338   
339 #ifdef DBUS_BUILD_X11
340   xdisplay = XOpenDisplay (NULL);
341   if (xdisplay != NULL)
342     {
343       verbose ("Successfully opened X display\n");
344       x_fd = ConnectionNumber (xdisplay);
345       XSetIOErrorHandler (x_io_error_handler);
346     }
347   else
348     x_fd = -1;
349 #else
350   verbose ("Compiled without X11 support\n");
351   x_fd = -1;
352 #endif
353
354   if (isatty (0))
355     tty_fd = 0;
356   else
357     tty_fd = -1;
358
359   if (tty_fd >= 0)
360     verbose ("stdin isatty(), monitoring it\n");
361   else
362     verbose ("stdin was not a TTY, not monitoring it\n");  
363   
364   if (tty_fd < 0 && x_fd < 0)
365     {
366       fprintf (stderr, "No terminal on standard input and no X display; cannot attach message bus to session lifetime\n");
367       exit (1);
368     }
369   
370   while (TRUE)
371     {
372       FD_ZERO (&read_set);
373       FD_ZERO (&err_set);
374
375       if (tty_fd >= 0)
376         {
377           FD_SET (tty_fd, &read_set);
378           FD_SET (tty_fd, &err_set);
379         }
380
381       if (x_fd >= 0)
382         {
383           FD_SET (x_fd, &read_set);
384           FD_SET (x_fd, &err_set);
385         }
386       
387       ret = select (MAX (tty_fd, x_fd) + 1,
388                     &read_set, NULL, &err_set, NULL);
389
390       if (got_sighup)
391         {
392           verbose ("Got SIGHUP, exiting\n");
393           kill_bus_and_exit ();
394         }
395       
396 #ifdef DBUS_BUILD_X11
397       /* Dump events on the floor, and let
398        * IO error handler run if we lose
399        * the X connection
400        */
401       if (x_fd >= 0)
402         verbose ("X fd condition reading = %d error = %d\n",
403                  FD_ISSET (x_fd, &read_set),
404                  FD_ISSET (x_fd, &err_set));
405       
406       if (xdisplay != NULL)
407         {      
408           while (XPending (xdisplay))
409             {
410               XEvent ignored;
411               XNextEvent (xdisplay, &ignored);
412             }
413         }
414 #endif
415
416       if (tty_fd >= 0)
417         {
418           if (FD_ISSET (tty_fd, &read_set))
419             {
420               int bytes_read;
421               char discard[512];
422
423               verbose ("TTY ready for reading\n");
424               
425               bytes_read = read (tty_fd, discard, sizeof (discard));
426
427               verbose ("Read %d bytes from TTY errno = %d\n",
428                        bytes_read, errno);
429               
430               if (bytes_read == 0)
431                 kill_bus_and_exit (); /* EOF */
432               else if (bytes_read < 0 && errno != EINTR)
433                 {
434                   /* This shouldn't happen I don't think; to avoid
435                    * spinning on the fd forever we exit.
436                    */
437                   fprintf (stderr, "dbus-launch: error reading from stdin: %s\n",
438                            strerror (errno));
439                   kill_bus_and_exit ();
440                 }
441             }
442           else if (FD_ISSET (tty_fd, &err_set))
443             {
444               verbose ("TTY has error condition\n");
445               
446               kill_bus_and_exit ();
447             }
448         }
449     }
450 }
451
452 static void
453 babysit (int   exit_with_session,
454          pid_t child_pid,
455          int   read_bus_pid_fd,  /* read pid from here */
456          int   write_bus_pid_fd) /* forward pid to here */
457 {
458   int ret;
459 #define MAX_PID_LEN 64
460   char buf[MAX_PID_LEN];
461   long val;
462   char *end;
463   int dev_null_fd;
464   
465   /* We chdir ("/") since we are persistent and daemon-like, and fork
466    * again so dbus-launch can reap the parent.  However, we don't
467    * setsid() or close fd 0 because the idea is to remain attached
468    * to the tty and the X server in order to kill the message bus
469    * when the session ends.
470    */
471
472   if (chdir ("/") < 0)
473     {
474       fprintf (stderr, "Could not change to root directory: %s\n",
475                strerror (errno));
476       exit (1);
477     }
478
479   /* Move stdout/stderr so we don't block an "eval" or otherwise
480    * lock up.
481    */
482   dev_null_fd = open ("/dev/null", O_RDWR);
483   if (dev_null_fd >= 0)
484     {
485       dup2 (dev_null_fd, 1);
486       dup2 (dev_null_fd, 2);
487     }
488   else
489     {
490       fprintf (stderr, "Failed to open /dev/null: %s\n",
491                strerror (errno));
492       /* continue, why not */
493     }
494   
495   ret = fork ();
496
497   if (ret < 0)
498     {
499       fprintf (stderr, "fork() failed in babysitter: %s\n",
500                strerror (errno));
501       exit (1);
502     }
503
504   if (ret > 0)
505     {
506       /* Parent reaps pre-fork part of bus daemon, then exits and is
507        * reaped so the babysitter isn't a zombie
508        */
509
510       verbose ("=== Babysitter's intermediate parent continues again\n");
511       
512       if (do_waitpid (child_pid) < 0)
513         {
514           /* shouldn't happen */
515           fprintf (stderr, "Failed waitpid() waiting for bus daemon's parent\n");
516           exit (1);
517         }
518
519       verbose ("Babysitter's intermediate parent exiting\n");
520       
521       exit (0);
522     }
523
524   /* Child continues */
525   verbose ("=== Babysitter process created\n");
526
527   verbose ("Reading PID from daemon\n");
528   /* Now read data */
529   switch (read_line (read_bus_pid_fd, buf, MAX_PID_LEN))
530     {
531     case READ_STATUS_OK:
532       break;
533     case READ_STATUS_EOF:
534       fprintf (stderr, "EOF reading PID from bus daemon\n");
535       exit (1);
536       break;
537     case READ_STATUS_ERROR:
538       fprintf (stderr, "Error reading PID from bus daemon: %s\n",
539                strerror (errno));
540       exit (1);
541       break;
542     }
543
544   end = NULL;
545   val = strtol (buf, &end, 0);
546   if (buf == end || end == NULL)
547     {
548       fprintf (stderr, "Failed to parse bus PID \"%s\": %s\n",
549                buf, strerror (errno));
550       exit (1);
551     }
552
553   bus_pid_to_kill = val;
554
555   verbose ("Got PID %ld from daemon\n",
556            (long) bus_pid_to_kill);
557   
558   /* Write data to launcher */
559   write_pid (write_bus_pid_fd, bus_pid_to_kill);
560   close (write_bus_pid_fd);
561   
562   if (exit_with_session)
563     {
564       /* Bus is now started and launcher has needed info;
565        * we connect to X display and tty and wait to
566        * kill bus if requested.
567        */
568       
569       kill_bus_when_session_ends ();
570     }
571
572   verbose ("Babysitter exiting\n");
573   
574   exit (0);
575 }
576
577 #define READ_END  0
578 #define WRITE_END 1
579
580 int
581 main (int argc, char **argv)
582 {
583   const char *prev_arg;
584   const char *shname;
585   const char *runprog = NULL;
586   int remaining_args = 0;
587   int exit_with_session;
588   int c_shell_syntax = FALSE;
589   int bourne_shell_syntax = FALSE;
590   int auto_shell_syntax = FALSE;
591   int i;  
592   int ret;
593   int bus_pid_to_launcher_pipe[2];
594   int bus_pid_to_babysitter_pipe[2];
595   int bus_address_to_launcher_pipe[2];
596   char *config_file;
597   
598   exit_with_session = FALSE;
599   config_file = NULL;
600   
601   prev_arg = NULL;
602   i = 1;
603   while (i < argc)
604     {
605       const char *arg = argv[i];
606       
607       if (strcmp (arg, "--help") == 0 ||
608           strcmp (arg, "-h") == 0 ||
609           strcmp (arg, "-?") == 0)
610         usage (0);
611       else if (strcmp (arg, "--auto-syntax") == 0)
612         auto_shell_syntax = TRUE;
613       else if (strcmp (arg, "-c") == 0 ||
614                strcmp (arg, "--csh-syntax") == 0)
615         c_shell_syntax = TRUE;
616       else if (strcmp (arg, "-s") == 0 ||
617                strcmp (arg, "--sh-syntax") == 0)
618         bourne_shell_syntax = TRUE;
619       else if (strcmp (arg, "--version") == 0)
620         version ();
621       else if (strcmp (arg, "--exit-with-session") == 0)
622         exit_with_session = TRUE;
623       else if (strstr (arg, "--config-file=") == arg)
624         {
625           const char *file;
626
627           if (config_file != NULL)
628             {
629               fprintf (stderr, "--config-file given twice\n");
630               exit (1);
631             }
632           
633           file = strchr (arg, '=');
634           ++file;
635
636           config_file = xstrdup (file);
637         }
638       else if (prev_arg &&
639                strcmp (prev_arg, "--config-file") == 0)
640         {
641           if (config_file != NULL)
642             {
643               fprintf (stderr, "--config-file given twice\n");
644               exit (1);
645             }
646
647           config_file = xstrdup (arg);
648         }
649       else if (strcmp (arg, "--config-file") == 0)
650         ; /* wait for next arg */
651       else
652         {
653           runprog = arg;
654           remaining_args = i+1;
655           break;
656         }
657       
658       prev_arg = arg;
659       
660       ++i;
661     }
662
663   if (exit_with_session)
664     verbose ("--exit-with-session enabled\n");
665
666   if (auto_shell_syntax)
667     {
668       if ((shname = getenv ("SHELL")) != NULL)
669        {
670          if (!strncmp (shname + strlen (shname) - 3, "csh", 3))
671            c_shell_syntax = TRUE;
672          else
673            bourne_shell_syntax = TRUE;
674        }
675       else
676        bourne_shell_syntax = TRUE;
677     }  
678
679   if (pipe (bus_pid_to_launcher_pipe) < 0 ||
680       pipe (bus_address_to_launcher_pipe) < 0)
681     {
682       fprintf (stderr,
683                "Failed to create pipe: %s\n",
684                strerror (errno));
685       exit (1);
686     }
687
688   bus_pid_to_babysitter_pipe[READ_END] = -1;
689   bus_pid_to_babysitter_pipe[WRITE_END] = -1;
690   
691   ret = fork ();
692   if (ret < 0)
693     {
694       fprintf (stderr, "Failed to fork: %s\n",
695                strerror (errno));
696       exit (1);
697     }
698
699   if (ret == 0)
700     {
701       /* Child */
702 #define MAX_FD_LEN 64
703       char write_pid_fd_as_string[MAX_FD_LEN];
704       char write_address_fd_as_string[MAX_FD_LEN];
705
706       verbose ("=== Babysitter's intermediate parent created\n");
707       
708       /* Fork once more to create babysitter */
709       
710       if (pipe (bus_pid_to_babysitter_pipe) < 0)
711         {
712           fprintf (stderr,
713                    "Failed to create pipe: %s\n",
714                    strerror (errno));
715           exit (1);              
716         }
717       
718       ret = fork ();
719       if (ret < 0)
720         {
721           fprintf (stderr, "Failed to fork: %s\n",
722                    strerror (errno));
723           exit (1);
724         }
725       
726       if (ret > 0)
727         {
728           /* In babysitter */
729           verbose ("=== Babysitter's intermediate parent continues\n");
730           
731           close (bus_pid_to_launcher_pipe[READ_END]);
732           close (bus_address_to_launcher_pipe[READ_END]);
733           close (bus_address_to_launcher_pipe[WRITE_END]);
734           close (bus_pid_to_babysitter_pipe[WRITE_END]);
735           
736           /* babysit() will fork *again*
737            * and will also reap the pre-forked bus
738            * daemon
739            */
740           babysit (exit_with_session, ret,
741                    bus_pid_to_babysitter_pipe[READ_END],
742                    bus_pid_to_launcher_pipe[WRITE_END]);
743           exit (0);
744         }
745
746       verbose ("=== Bus exec process created\n");
747       
748       /* Now we are the bus process (well, almost;
749        * dbus-daemon-1 itself forks again)
750        */
751       close (bus_pid_to_launcher_pipe[READ_END]);
752       close (bus_address_to_launcher_pipe[READ_END]);
753       close (bus_pid_to_babysitter_pipe[READ_END]);
754       close (bus_pid_to_launcher_pipe[WRITE_END]);
755
756       sprintf (write_pid_fd_as_string,
757                "%d", bus_pid_to_babysitter_pipe[WRITE_END]);
758
759       sprintf (write_address_fd_as_string,
760                "%d", bus_address_to_launcher_pipe[WRITE_END]);
761
762       verbose ("Calling exec()\n");
763       
764       execlp ("dbus-daemon-1",
765               "dbus-daemon-1",
766               "--fork",
767               "--print-pid", write_pid_fd_as_string,
768               "--print-address", write_address_fd_as_string,
769               config_file ? "--config-file" : "--session",
770               config_file, /* has to be last in this varargs list */
771               NULL);
772
773       fprintf (stderr,
774                "Failed to execute message bus daemon: %s\n",
775                strerror (errno));
776       exit (1);
777     }
778   else
779     {
780       /* Parent */
781 #define MAX_ADDR_LEN 512
782       pid_t bus_pid;  
783       char bus_address[MAX_ADDR_LEN];
784
785       verbose ("=== Parent dbus-launch continues\n");
786       
787       close (bus_pid_to_launcher_pipe[WRITE_END]);
788       close (bus_address_to_launcher_pipe[WRITE_END]);
789
790       verbose ("Waiting for babysitter's intermediate parent\n");
791       
792       /* Immediately reap parent of babysitter
793        * (which was created just for us to reap)
794        */
795       if (do_waitpid (ret) < 0)
796         {
797           fprintf (stderr, "Failed to waitpid() for babysitter intermediate process: %s\n",
798                    strerror (errno));
799           exit (1);
800         }
801
802       verbose ("Reading address from bus\n");
803       
804       /* Read the pipe data, print, and exit */
805       switch (read_line (bus_address_to_launcher_pipe[READ_END],
806                          bus_address, MAX_ADDR_LEN))
807         {
808         case READ_STATUS_OK:
809           break;
810         case READ_STATUS_EOF:
811           fprintf (stderr, "EOF in dbus-launch reading address from bus daemon\n");
812           exit (1);
813           break;
814         case READ_STATUS_ERROR:
815           fprintf (stderr, "Error in dbus-launch reading address from bus daemon: %s\n",
816                    strerror (errno));
817           exit (1);
818           break;
819         }
820         
821       close (bus_address_to_launcher_pipe[READ_END]);
822
823       verbose ("Reading PID from babysitter\n");
824       
825       switch (read_pid (bus_pid_to_launcher_pipe[READ_END], &bus_pid))
826         {
827         case READ_STATUS_OK:
828           break;
829         case READ_STATUS_EOF:
830           fprintf (stderr, "EOF in dbus-launch reading address from bus daemon\n");
831           exit (1);
832           break;
833         case READ_STATUS_ERROR:
834           fprintf (stderr, "Error in dbus-launch reading address from bus daemon: %s\n",
835                    strerror (errno));
836           exit (1);
837           break;
838         }
839
840       close (bus_pid_to_launcher_pipe[READ_END]);
841       
842       if (runprog)
843         {
844           char *envvar;
845           char **args;
846
847           envvar = malloc (strlen ("DBUS_SESSION_BUS_ADDRESS=") + strlen (bus_address) + 1);
848           args = malloc (sizeof (char *) * ((argc-remaining_args)+2));
849
850           if (envvar == NULL || args == NULL)
851             goto oom;
852
853           args[0] = xstrdup (runprog);
854           if (!args[0])
855             goto oom;
856           for (i = 1; i <= (argc-remaining_args); i++)
857             {
858               size_t len = strlen (argv[remaining_args+i-1])+1;
859               args[i] = malloc (len);
860               if (!args[i])
861                 goto oom;
862               strncpy (args[i], argv[remaining_args+i-1], len);
863             }
864           args[i] = NULL;
865
866           strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS=");
867           strcat (envvar, bus_address);
868           putenv (envvar);
869
870           execvp (runprog, args);
871           fprintf (stderr, "Couldn't exec %s: %s\n", runprog, strerror (errno));
872           exit (1);
873         }
874       else
875         {
876           if (c_shell_syntax)
877             printf ("setenv DBUS_SESSION_BUS_ADDRESS '%s'\n", bus_address);     
878           else
879             {
880               printf ("DBUS_SESSION_BUS_ADDRESS='%s'\n", bus_address);
881               if (bourne_shell_syntax)
882                 printf ("export DBUS_SESSION_BUS_ADDRESS\n");
883             }
884           if (c_shell_syntax)
885             printf ("set DBUS_SESSION_BUS_PID=%ld\n", (long) bus_pid);
886           else
887             printf ("DBUS_SESSION_BUS_PID=%ld\n", (long) bus_pid);
888         }
889           
890       verbose ("dbus-launch exiting\n");
891       
892       exit (0);
893     } 
894   
895   return 0;
896  oom:
897   fprintf (stderr, "Out of memory!");
898   exit (1);
899 }