dbus/tools dbus-launch.1,1.9,1.10 dbus-launch.c,1.21,1.22

Thiago J. Macieira thiago at kemper.freedesktop.org
Sat Mar 3 02:36:48 PST 2007


Update of /cvs/dbus/dbus/tools
In directory kemper:/tmp/cvs-serv26569/tools

Modified Files:
	dbus-launch.1 dbus-launch.c 
Log Message:
	* dbus/dbus-sysdeps-unix.c: capture the dbus-launch stderr
        output and add it to the DBusError message we return.

	* tools/dbus-launch.1:
	* tools/dbus-launch.c: Add option --close-stderr to, well,
	close stderr before starting dbus-daemon.


Index: dbus-launch.1
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-launch.1,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- dbus-launch.1	30 Oct 2006 06:29:58 -0000	1.9
+++ dbus-launch.1	3 Mar 2007 10:36:46 -0000	1.10
@@ -136,6 +136,13 @@
 byte order, not network byte order or any other canonical byte order.
 
 .TP
+.I "--close-stderr"
+Close the standard error output stream before starting the D-Bus
+daemon. This is useful if you want to capture dbus-launch error
+messages but you don't want dbus-daemon to keep the stream open to
+your application.
+
+.TP
 .I "--config-file=FILENAME"
 Pass \-\-config-file=FILENAME to the bus daemon, instead of passing it 
 the \-\-session argument. See the man page for dbus-daemon

Index: dbus-launch.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-launch.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- dbus-launch.c	26 Oct 2006 15:55:44 -0000	1.21
+++ dbus-launch.c	3 Mar 2007 10:36:46 -0000	1.22
@@ -596,6 +596,27 @@
   exit (0);
 }
 
+static void do_close_stderr (void)
+{
+  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...
+   */
+  int 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);
+}
+
 #define READ_END  0
 #define WRITE_END 1
 
@@ -613,7 +634,8 @@
   int auto_shell_syntax = FALSE;
   int autolaunch = FALSE;
   int requires_arg = FALSE;
-  int i;  
+  int close_stderr = FALSE;
+  int i;
   int ret;
   int bus_pid_to_launcher_pipe[2];
   int bus_pid_to_babysitter_pipe[2];
@@ -647,6 +669,8 @@
         version ();
       else if (strcmp (arg, "--exit-with-session") == 0)
         exit_with_session = TRUE;
+      else if (strcmp (arg, "--close-stderr") == 0)
+        close_stderr = TRUE;
       else if (strstr (arg, "--autolaunch=") == arg)
         {
           const char *s;
@@ -837,6 +861,9 @@
       char write_pid_fd_as_string[MAX_FD_LEN];
       char write_address_fd_as_string[MAX_FD_LEN];
 
+      if (close_stderr)
+	do_close_stderr ();
+
       verbose ("=== Babysitter's intermediate parent created\n");
 
       /* Fork once more to create babysitter */
@@ -859,7 +886,7 @@
           close (bus_address_to_launcher_pipe[READ_END]);
           close (bus_address_to_launcher_pipe[WRITE_END]);
           close (bus_pid_to_babysitter_pipe[WRITE_END]);
-          
+
           /* babysit() will fork *again*
            * and will also reap the pre-forked bus
            * daemon



More information about the dbus-commit mailing list