dbus/dbus dbus-sysdeps-unix.c,1.18,1.19

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


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

Modified Files:
	dbus-sysdeps-unix.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-sysdeps-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps-unix.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- dbus-sysdeps-unix.c	1 Jan 2007 21:29:59 -0000	1.18
+++ dbus-sysdeps-unix.c	3 Mar 2007 10:36:45 -0000	1.19
@@ -2434,8 +2434,9 @@
 _dbus_get_autolaunch_address (DBusString *address,
                               DBusError  *error)
 {
-  static char *argv[5];
-  int address_pipe[2];
+  static char *argv[6];
+  int address_pipe[2] = { -1, -1 };
+  int errors_pipe[2] = { -1, -1 };
   pid_t pid;
   int ret;
   int status;
@@ -2464,6 +2465,8 @@
   ++i;
   argv[i] = "--binary-syntax";
   ++i;
+  argv[i] = "--close-stderr";
+  ++i;
   argv[i] = NULL;
   ++i;
 
@@ -2482,6 +2485,15 @@
                      _dbus_strerror (errno));
       goto out;
     }
+  if (pipe (errors_pipe) < 0)
+    {
+      dbus_set_error (error, _dbus_error_from_errno (errno),
+                      "Failed to create a pipe: %s",
+                      _dbus_strerror (errno));
+      _dbus_verbose ("Failed to create a pipe to call dbus-launch: %s\n",
+                     _dbus_strerror (errno));
+      goto out;
+    }
 
   pid = fork ();
   if (pid < 0)
@@ -2504,6 +2516,7 @@
 
       /* set-up stdXXX */
       close (address_pipe[READ_END]);
+      close (errors_pipe[READ_END]);
       close (0);                /* close stdin */
       close (1);                /* close stdout */
       close (2);                /* close stderr */
@@ -2512,11 +2525,12 @@
         _exit (1);
       if (dup2 (address_pipe[WRITE_END], 1) == -1)
         _exit (1);
-      if (dup2 (fd, 2) == -1)
+      if (dup2 (errors_pipe[WRITE_END], 2) == -1)
         _exit (1);
 
       close (fd);
       close (address_pipe[WRITE_END]);
+      close (errors_pipe[WRITE_END]);
 
       execv (DBUS_BINDIR "/dbus-launch", argv);
 
@@ -2529,6 +2543,10 @@
 
   /* parent process */
   close (address_pipe[WRITE_END]);
+  close (errors_pipe[WRITE_END]);
+  address_pipe[WRITE_END] = -1;
+  errors_pipe[WRITE_END] = -1;
+
   ret = 0;
   do 
     {
@@ -2549,9 +2567,23 @@
       _dbus_string_get_length (address) == orig_len)
     {
       /* The process ended with error */
+      DBusString error_message;
+      _dbus_string_init (&error_message);
+      ret = 0;
+      do
+	{
+	  ret = _dbus_read (errors_pipe[READ_END], &error_message, 1024);
+	}
+      while (ret > 0);
+
       _dbus_string_set_length (address, orig_len);
-      dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED,
-                      "Failed to execute dbus-launch to autolaunch D-Bus session");
+      if (_dbus_string_get_length (&error_message) > 0)
+	dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED,
+			"dbus-launch failed to autolaunch D-Bus session: %s",
+			_dbus_string_get_data (&error_message));
+      else
+	dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED,
+			"Failed to execute dbus-launch to autolaunch D-Bus session");
       goto out;
     }
 
@@ -2562,7 +2594,16 @@
     _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   else
     _DBUS_ASSERT_ERROR_IS_SET (error);
-  
+
+  if (address_pipe[0] != -1)
+    close (address_pipe[0]);
+  if (address_pipe[1] != -1)
+    close (address_pipe[1]);
+  if (errors_pipe[0] != -1)
+    close (errors_pipe[0]);
+  if (errors_pipe[1] != -1)
+    close (errors_pipe[1]);
+
   _dbus_string_free (&uuid);
   return retval;
 }



More information about the dbus-commit mailing list