dbus/dbus dbus-sysdeps-unix.c,1.16,1.16.2.1

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


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

Modified Files:
      Tag: DBUS_1_0
	dbus-sysdeps-unix.c 
Log Message:
Backport from MAIN:
	* 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.

I hope adding an option to dbus-launch in the 1.0.x series was ok.


Index: dbus-sysdeps-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps-unix.c,v
retrieving revision 1.16
retrieving revision 1.16.2.1
diff -u -d -r1.16 -r1.16.2.1
--- dbus-sysdeps-unix.c	1 Nov 2006 23:30:46 -0000	1.16
+++ dbus-sysdeps-unix.c	3 Mar 2007 10:38:20 -0000	1.16.2.1
@@ -2369,8 +2369,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;
@@ -2399,6 +2400,8 @@
   ++i;
   argv[i] = "--binary-syntax";
   ++i;
+  argv[i] = "--close-stderr";
+  ++i;
   argv[i] = NULL;
   ++i;
 
@@ -2417,6 +2420,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)
@@ -2439,6 +2451,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 */
@@ -2447,11 +2460,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);
 
@@ -2464,6 +2478,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 
     {
@@ -2484,7 +2502,21 @@
       _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);
+      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;
@@ -2498,6 +2530,15 @@
   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