dbus/bus bus.c, 1.76, 1.77 bus.h, 1.29, 1.30 config-parser.c, 1.47, 1.48 main.c, 1.37, 1.38 test.c, 1.27, 1.28

Havoc Pennington hp at kemper.freedesktop.org
Mon Mar 12 15:52:42 PDT 2007


Update of /cvs/dbus/dbus/bus
In directory kemper:/tmp/cvs-serv25302/bus

Modified Files:
	bus.c bus.h config-parser.c main.c test.c 
Log Message:
2007-03-11  Havoc Pennington  <hp at redhat.com>

	* tools/dbus-launch.c (do_close_stderr): fix C89 problem and
	formatting problem

	* Mostly fix the DBusPipe mess.
	- put line break after function return types
	- put space before parens
	- do not pass structs around by value
	- don't use dbus_strerror after calling supposedly cross-platform
	api
	- don't name pipe variables "fd"
	- abstract special fd numbers like -1 and 1



Index: bus.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/bus.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- bus.c	10 Mar 2007 09:10:36 -0000	1.76
+++ bus.c	12 Mar 2007 22:52:39 -0000	1.77
@@ -527,8 +527,8 @@
 BusContext*
 bus_context_new (const DBusString *config_file,
                  ForceForkSetting  force_fork,
-                 DBusPipe          print_addr_fd,
-                 DBusPipe          print_pid_fd,
+                 DBusPipe         *print_addr_pipe,
+                 DBusPipe         *print_pid_pipe,
                  DBusError        *error)
 {
   BusContext *context;
@@ -598,12 +598,12 @@
   if (!dbus_server_allocate_data_slot (&server_data_slot))
     _dbus_assert_not_reached ("second ref of server data slot failed");
 
-  /* Note that we don't know whether the print_addr_fd is
+  /* Note that we don't know whether the print_addr_pipe is
    * one of the sockets we're using to listen on, or some
    * other random thing. But I think the answer is "don't do
    * that then"
    */
-  if (_dbus_pipe_is_valid(print_addr_fd))
+  if (print_addr_pipe != NULL && _dbus_pipe_is_valid (print_addr_pipe))
     {
       DBusString addr;
       const char *a = bus_context_get_address (context);
@@ -625,17 +625,20 @@
         }
 
       bytes = _dbus_string_get_length (&addr);
-      if (_dbus_pipe_write(print_addr_fd, &addr, 0, bytes) != bytes)
+      if (_dbus_pipe_write (print_addr_pipe, &addr, 0, bytes, error) != bytes)
         {
-          dbus_set_error (error, DBUS_ERROR_FAILED,
-                          "Printing message bus address: %s\n",
-                          _dbus_strerror (errno));
+          /* pipe write returns an error on failure but not short write */
+          if (error != NULL && !dbus_error_is_set (error))
+            {
+              dbus_set_error (error, DBUS_ERROR_FAILED,
+                              "Printing message bus address: did not write all bytes\n");
+            }
           _dbus_string_free (&addr);
           goto failed;
         }
 
-      if (_dbus_pipe_is_special(print_addr_fd))
-        _dbus_pipe_close(print_addr_fd, NULL);
+      if (!_dbus_pipe_is_stdout_or_stderr (print_addr_pipe))
+        _dbus_pipe_close (print_addr_pipe, NULL);
 
       _dbus_string_free (&addr);
     }
@@ -681,7 +684,7 @@
         _dbus_string_init_const (&u, context->pidfile);
       
       if (!_dbus_become_daemon (context->pidfile ? &u : NULL, 
-				print_pid_fd,
+				print_pid_pipe,
 				error))
 	{
 	  _DBUS_ASSERT_ERROR_IS_SET (error);
@@ -706,7 +709,7 @@
     }
 
   /* Write PID if requested */
-  if (_dbus_pipe_is_valid(print_pid_fd))
+  if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
     {
       DBusString pid;
       int bytes;
@@ -726,17 +729,20 @@
         }
 
       bytes = _dbus_string_get_length (&pid);
-      if (_dbus_pipe_write (print_pid_fd, &pid, 0, bytes) != bytes)
+      if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
         {
-          dbus_set_error (error, DBUS_ERROR_FAILED,
-                          "Printing message bus PID: %s\n",
-                          _dbus_strerror (errno));
+          /* pipe_write sets error on failure but not short write */
+          if (error != NULL && !dbus_error_is_set (error))
+            {
+              dbus_set_error (error, DBUS_ERROR_FAILED,
+                              "Printing message bus PID: did not write enough bytes\n");
+            }
           _dbus_string_free (&pid);
           goto failed;
         }
 
-      if (_dbus_pipe_is_special (print_pid_fd))
-        _dbus_pipe_close (print_pid_fd, NULL);
+      if (!_dbus_pipe_is_stdout_or_stderr (print_pid_pipe))
+        _dbus_pipe_close (print_pid_pipe, NULL);
       
       _dbus_string_free (&pid);
     }

Index: bus.h
===================================================================
RCS file: /cvs/dbus/dbus/bus/bus.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- bus.h	10 Mar 2007 09:10:36 -0000	1.29
+++ bus.h	12 Mar 2007 22:52:39 -0000	1.30
@@ -70,8 +70,8 @@
 
 BusContext*       bus_context_new                                (const DBusString *config_file,
                                                                   ForceForkSetting  force_fork,
-                                                                  DBusPipe         print_addr_fd,
-                                                                  DBusPipe         print_pid_fd,
+                                                                  DBusPipe         *print_addr_pipe,
+                                                                  DBusPipe         *print_pid_pipe,
                                                                   DBusError        *error);
 dbus_bool_t       bus_context_reload_config                      (BusContext       *context,
 								  DBusError        *error);

Index: config-parser.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/config-parser.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- config-parser.c	26 Jan 2007 16:10:09 -0000	1.47
+++ config-parser.c	12 Mar 2007 22:52:39 -0000	1.48
@@ -27,6 +27,7 @@
 #include "selinux.h"
 #include <dbus/dbus-list.h>
 #include <dbus/dbus-internals.h>
+#include <dbus/dbus-userdb.h>
 #include <string.h>
 
 typedef enum

Index: main.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/main.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- main.c	10 Mar 2007 09:10:36 -0000	1.37
+++ main.c	12 Mar 2007 22:52:39 -0000	1.38
@@ -247,8 +247,8 @@
   DBusString addr_fd;
   DBusString pid_fd;
   const char *prev_arg;
-  DBusPipe print_addr_fd;
-  DBusPipe print_pid_fd;
+  DBusPipe print_addr_pipe;
+  DBusPipe print_pid_pipe;
   int i;
   dbus_bool_t print_address;
   dbus_bool_t print_pid;
@@ -387,10 +387,10 @@
       usage ();
     }
 
-  print_addr_fd = _dbus_pipe_init(-1);
+  _dbus_pipe_invalidate (&print_addr_pipe);
   if (print_address)
     {
-      print_addr_fd = _dbus_pipe_init(1); /* stdout */
+      _dbus_pipe_init_stdout (&print_addr_pipe);
       if (_dbus_string_get_length (&addr_fd) > 0)
         {
           long val;
@@ -404,15 +404,15 @@
               exit (1);
             }
 
-          print_addr_fd = _dbus_pipe_init(val);
+          _dbus_pipe_init (&print_addr_pipe, val);
         }
     }
   _dbus_string_free (&addr_fd);
 
-  print_pid_fd = _dbus_pipe_init(-1);
+  _dbus_pipe_invalidate (&print_pid_pipe);
   if (print_pid)
     {
-      print_pid_fd = _dbus_pipe_init(1); /* stdout */
+      _dbus_pipe_init_stdout (&print_pid_pipe);
       if (_dbus_string_get_length (&pid_fd) > 0)
         {
           long val;
@@ -426,7 +426,7 @@
               exit (1);
             }
 
-          print_pid_fd = _dbus_pipe_init(val);
+          _dbus_pipe_init (&print_pid_pipe, val);
         }
     }
   _dbus_string_free (&pid_fd);
@@ -439,7 +439,7 @@
 
   dbus_error_init (&error);
   context = bus_context_new (&config_file, force_fork,
-                             print_addr_fd, print_pid_fd,
+                             &print_addr_pipe, &print_pid_pipe,
                              &error);
   _dbus_string_free (&config_file);
   if (context == NULL)

Index: test.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/test.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- test.c	10 Mar 2007 09:10:36 -0000	1.27
+++ test.c	12 Mar 2007 22:52:39 -0000	1.28
@@ -298,7 +298,6 @@
   DBusString config_file;
   DBusString relative;
   BusContext *context;
-  DBusPipe pipe;
   
   if (!_dbus_string_init (&config_file))
     {
@@ -324,8 +323,7 @@
     }
   
   dbus_error_init (&error);
-  pipe = _dbus_pipe_init(-1);
-  context = bus_context_new (&config_file, FALSE, pipe, pipe, &error);
+  context = bus_context_new (&config_file, FALSE, NULL, NULL, &error);
   if (context == NULL)
     {
       _DBUS_ASSERT_ERROR_IS_SET (&error);



More information about the dbus-commit mailing list