dbus/dbus Makefile.am, 1.81, 1.82 dbus-server-debug-pipe.c, 1.20, 1.21 dbus-server-unix.c, 1.30, 1.31 dbus-spawn.c, 1.23, 1.24 dbus-sysdeps-unix.c, 1.3, 1.4 dbus-sysdeps-util-unix.c, 1.6, 1.7 dbus-sysdeps.h, 1.56, 1.57 dbus-transport-unix.c, 1.51, 1.52

Havoc Pennington hp at kemper.freedesktop.org
Sat Sep 16 08:34:37 PDT 2006


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

Modified Files:
	Makefile.am dbus-server-debug-pipe.c dbus-server-unix.c 
	dbus-spawn.c dbus-sysdeps-unix.c dbus-sysdeps-util-unix.c 
	dbus-sysdeps.h dbus-transport-unix.c 
Log Message:
2006-09-16  Havoc Pennington  <hp at redhat.com>

	* dbus/dbus-sysdeps-unix.h: small change to Peter's patch to make
	dbus-sysdeps-unix-util.c build, add unix-specific sysdeps header.

	* dbus/dbus-sysdeps.h, dbus-sysdeps-unix.c: patch from Peter 
	Kümmel bug #8249 to make the sysdeps.h read/write/open/close
	functions specifically for sockets only, and move generic 
	read/write/open/close into unix-specific code.



Index: Makefile.am
===================================================================
RCS file: /cvs/dbus/dbus/dbus/Makefile.am,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- Makefile.am	10 Sep 2006 21:37:10 -0000	1.81
+++ Makefile.am	16 Sep 2006 15:34:34 -0000	1.82
@@ -104,8 +104,9 @@
 	dbus-string.h				\
 	dbus-string-private.h			\
 	dbus-sysdeps.c				\
-	dbus-sysdeps-unix.c			\
 	dbus-sysdeps.h				\
+	dbus-sysdeps-unix.c			\
+	dbus-sysdeps-unix.h			\
 	dbus-userdb.c				\
 	dbus-userdb.h
 

Index: dbus-server-debug-pipe.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server-debug-pipe.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- dbus-server-debug-pipe.c	14 Aug 2006 19:11:35 -0000	1.20
+++ dbus-server-debug-pipe.c	16 Sep 2006 15:34:34 -0000	1.21
@@ -260,8 +260,8 @@
                                                  NULL, &address);
   if (client_transport == NULL)
     {
-      _dbus_close (client_fd, NULL);
-      _dbus_close (server_fd, NULL);
+      _dbus_close_socket (client_fd, NULL);
+      _dbus_close_socket (server_fd, NULL);
       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
       _dbus_string_free (&address);
       return NULL;
@@ -276,7 +276,7 @@
   if (server_transport == NULL)
     {
       _dbus_transport_unref (client_transport);
-      _dbus_close (server_fd, NULL);
+      _dbus_close_socket (server_fd, NULL);
       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
       return NULL;
     }

Index: dbus-server-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server-unix.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- dbus-server-unix.c	7 Sep 2006 18:24:11 -0000	1.30
+++ dbus-server-unix.c	16 Sep 2006 15:34:34 -0000	1.31
@@ -102,7 +102,7 @@
   transport = _dbus_transport_new_for_fd (client_fd, &server->guid_hex, NULL);
   if (transport == NULL)
     {
-      _dbus_close (client_fd, NULL);
+      _dbus_close_socket (client_fd, NULL);
       SERVER_UNLOCK (server);
       return FALSE;
     }
@@ -219,7 +219,7 @@
       unix_server->watch = NULL;
     }
   
-  _dbus_close (unix_server->fd, NULL);
+  _dbus_close_socket (unix_server->fd, NULL);
   unix_server->fd = -1;
 
   if (unix_server->socket_name != NULL)
@@ -373,7 +373,7 @@
   return server;
 
  failed_2:
-  _dbus_close (listen_fd, NULL);
+  _dbus_close_socket (listen_fd, NULL);
  failed_1:
   dbus_free (path_copy);
  failed_0:
@@ -436,7 +436,7 @@
   if (server == NULL)
     {
       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-      _dbus_close (listen_fd, NULL);
+      _dbus_close_socket (listen_fd, NULL);
       _dbus_string_free (&address);
       return NULL;
     }

Index: dbus-spawn.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-spawn.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- dbus-spawn.c	7 Sep 2006 18:28:13 -0000	1.23
+++ dbus-spawn.c	16 Sep 2006 15:34:34 -0000	1.24
@@ -276,13 +276,13 @@
            * a hangup and then the babysitter will
            * quit itself.
            */
-          _dbus_close (sitter->socket_to_babysitter, NULL);
+          _dbus_close_socket (sitter->socket_to_babysitter, NULL);
           sitter->socket_to_babysitter = -1;
         }
 
       if (sitter->error_pipe_from_child >= 0)
         {
-          _dbus_close (sitter->error_pipe_from_child, NULL);
+          _dbus_close_socket (sitter->error_pipe_from_child, NULL);
           sitter->error_pipe_from_child = -1;
         }
 
@@ -470,7 +470,7 @@
 close_socket_to_babysitter (DBusBabysitter *sitter)
 {
   _dbus_verbose ("Closing babysitter\n");
-  _dbus_close (sitter->socket_to_babysitter, NULL);
+  _dbus_close_socket (sitter->socket_to_babysitter, NULL);
   sitter->socket_to_babysitter = -1;
 }
 
@@ -478,7 +478,7 @@
 close_error_pipe_from_child (DBusBabysitter *sitter)
 {
   _dbus_verbose ("Closing child error\n");
-  _dbus_close (sitter->error_pipe_from_child, NULL);
+  _dbus_close_socket (sitter->error_pipe_from_child, NULL);
   sitter->error_pipe_from_child = -1;
 }
 
@@ -753,7 +753,7 @@
     return -1;
   else
     {
-      ret = _dbus_close (*fd, NULL);
+      ret = _dbus_close_socket (*fd, NULL);
       *fd = -1;
     }
 

Index: dbus-sysdeps-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps-unix.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dbus-sysdeps-unix.c	14 Sep 2006 05:07:11 -0000	1.3
+++ dbus-sysdeps-unix.c	16 Sep 2006 15:34:34 -0000	1.4
@@ -24,6 +24,7 @@
 
 #include "dbus-internals.h"
 #include "dbus-sysdeps.h"
+#include "dbus-sysdeps-unix.h"
 #include "dbus-threads.h"
 #include "dbus-protocol.h"
 #include "dbus-string.h"
@@ -76,6 +77,54 @@
  * @{
  */
 
+dbus_bool_t
+_dbus_open_socket (int              *fd,
+                   int               domain,
+                   int               type,
+                   int               protocol)
+{
+  *fd = socket (domain, type, protocol);
+  return fd >= 0;
+}
+
+dbus_bool_t 
+_dbus_close_socket (int               fd,
+                    DBusError        *error)
+{
+  return _dbus_close (fd, error);
+}
+
+int
+_dbus_read_socket (int               fd,
+                   DBusString       *buffer,
+                   int               count)
+{
+  return _dbus_read (fd, buffer, count);
+}
+
+int
+_dbus_write_socket (int               fd,
+                    const DBusString *buffer,
+                    int               start,
+                    int               len)
+{
+  return _dbus_write (fd, buffer, start, len);
+}
+
+int
+_dbus_write_socket_two (int               fd,
+                        const DBusString *buffer1,
+                        int               start1,
+                        int               len1,
+                        const DBusString *buffer2,
+                        int               start2,
+                        int               len2)
+{
+  return _dbus_write_two (fd, buffer1, start1, len1,
+                          buffer2, start2, len2);
+}
+
+
 /**
  * Thin wrapper around the read() system call that appends
  * the data it reads to the DBusString buffer. It appends
@@ -306,9 +355,8 @@
   _dbus_verbose ("connecting to unix socket %s abstract=%d\n",
                  path, abstract);
   
-  fd = socket (PF_UNIX, SOCK_STREAM, 0);
   
-  if (fd < 0)
+  if (!_dbus_open_socket (&fd, PF_UNIX, SOCK_STREAM, 0))
     {
       dbus_set_error (error,
                       _dbus_error_from_errno (errno),
@@ -442,9 +490,7 @@
   _dbus_verbose ("listening on unix socket %s abstract=%d\n",
                  path, abstract);
   
-  listen_fd = socket (PF_UNIX, SOCK_STREAM, 0);
-  
-  if (listen_fd < 0)
+  if (!_dbus_open_socket (&listen_fd, PF_UNIX, SOCK_STREAM, 0))
     {
       dbus_set_error (error, _dbus_error_from_errno (errno),
                       "Failed to create socket \"%s\": %s",
@@ -578,10 +624,9 @@
   struct in_addr *haddr;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ 
   
-  fd = socket (AF_INET, SOCK_STREAM, 0);
-  
-  if (fd < 0)
+  if (!_dbus_open_socket (&fd, AF_INET, SOCK_STREAM, 0))
     {
       dbus_set_error (error,
                       _dbus_error_from_errno (errno),
@@ -658,9 +703,8 @@
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   
-  listen_fd = socket (AF_INET, SOCK_STREAM, 0);
   
-  if (listen_fd < 0)
+  if (!_dbus_open_socket (&listen_fd, AF_INET, SOCK_STREAM, 0))
     {
       dbus_set_error (error, _dbus_error_from_errno (errno),
                       "Failed to create socket \"%s:%d\": %s",

Index: dbus-sysdeps-util-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps-util-unix.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- dbus-sysdeps-util-unix.c	14 Sep 2006 05:41:20 -0000	1.6
+++ dbus-sysdeps-util-unix.c	16 Sep 2006 15:34:34 -0000	1.7
@@ -22,6 +22,7 @@
  *
  */
 #include "dbus-sysdeps.h"
+#include "dbus-sysdeps-unix.h"
 #include "dbus-internals.h"
 #include "dbus-protocol.h"
 #include "dbus-string.h"
@@ -152,7 +153,7 @@
 	    }
 	  
 	  bytes = _dbus_string_get_length (&pid);
-	  if (_dbus_write (print_pid_fd, &pid, 0, bytes) != bytes)
+	  if (_dbus_write_socket (print_pid_fd, &pid, 0, bytes) != bytes)
 	    {
 	      dbus_set_error (error, DBUS_ERROR_FAILED,
 			      "Printing message bus PID: %s\n",

Index: dbus-sysdeps.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.h,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- dbus-sysdeps.h	10 Sep 2006 21:37:10 -0000	1.56
+++ dbus-sysdeps.h	16 Sep 2006 15:34:34 -0000	1.57
@@ -74,20 +74,6 @@
 dbus_bool_t _dbus_setenv (const char *varname,
 			  const char *value);
 
-int _dbus_read      (int               fd,
-                     DBusString       *buffer,
-                     int               count);
-int _dbus_write     (int               fd,
-                     const DBusString *buffer,
-                     int               start,
-                     int               len);
-int _dbus_write_two (int               fd,
-                     const DBusString *buffer1,
-                     int               start1,
-                     int               len1,
-                     const DBusString *buffer2,
-                     int               start2,
-                     int               len2);
 
 typedef unsigned long dbus_pid_t;
 typedef unsigned long dbus_uid_t;
@@ -101,15 +87,39 @@
 #define DBUS_UID_FORMAT "%lu"
 #define DBUS_GID_FORMAT "%lu"
 
+
 /**
- * Struct representing socket credentials
+ * Socket interface
+ *
+ *  @todo Use for the file descriptors a struct
+ *           - struct DBusSocket{ int d; }; -
+ *        instead of int to get type-safety which 
+ *        will be checked by the compiler.
+ * 
  */
-typedef struct
-{
-  dbus_pid_t pid; /**< process ID or DBUS_PID_UNSET */
-  dbus_uid_t uid; /**< user ID or DBUS_UID_UNSET */
-  dbus_gid_t gid; /**< group ID or DBUS_GID_UNSET */
-} DBusCredentials;
+
+dbus_bool_t _dbus_open_socket      (int              *fd,
+                                    int               domain, 
+                                    int               type, 
+                                    int               protocol);
+dbus_bool_t _dbus_close_socket     (int               fd,
+                                    DBusError        *error);
+int         _dbus_read_socket      (int               fd,
+                                    DBusString       *buffer,
+                                    int               count);
+int         _dbus_write_socket     (int               fd,
+                                    const DBusString *buffer,
+                                    int               start,
+                                    int               len);
+int         _dbus_write_socket_two (int               fd,
+                                    const DBusString *buffer1,
+                                    int               start1,
+                                    int               len1,
+                                    const DBusString *buffer2,
+                                    int               start2,
+                                    int               len2);
+
+
 
 int _dbus_connect_unix_socket (const char     *path,
                                dbus_bool_t     abstract,
@@ -125,6 +135,16 @@
                                DBusError      *error);
 int _dbus_accept              (int             listen_fd);
 
+/**
+ * Struct representing socket credentials
+ */
+typedef struct
+{
+  dbus_pid_t pid; /**< process ID or DBUS_PID_UNSET */
+  dbus_uid_t uid; /**< user ID or DBUS_UID_UNSET */
+  dbus_gid_t gid; /**< group ID or DBUS_GID_UNSET */
+} DBusCredentials;
+
 dbus_bool_t _dbus_read_credentials_unix_socket (int              client_fd,
                                                 DBusCredentials *credentials,
                                                 DBusError       *error);
@@ -223,7 +243,10 @@
 void _dbus_get_current_time (long *tv_sec,
                              long *tv_usec);
 
-
+/**
+ * File/directory interface
+ */
+dbus_bool_t _dbus_file_exists         (const char       *file);
 dbus_bool_t _dbus_file_get_contents   (DBusString       *str,
                                        const DBusString *filename,
                                        DBusError        *error);
@@ -258,6 +281,13 @@
 dbus_bool_t  _dbus_check_dir_is_private_to_user    (DBusString *dir,
                                                     DBusError *error);
 
+void _dbus_fd_set_close_on_exec (int fd);
+
+const char* _dbus_get_tmpdir      (void);
+
+/**
+ * Random numbers 
+ */
 void        _dbus_generate_pseudorandom_bytes_buffer (char *buffer,
                                                       int   n_bytes);
 void        _dbus_generate_random_bytes_buffer (char       *buffer,
@@ -272,7 +302,6 @@
 
 void _dbus_disable_sigpipe (void);
 
-void _dbus_fd_set_close_on_exec (int fd);
 
 void _dbus_exit (int code) _DBUS_GNUC_NORETURN;
 
@@ -302,8 +331,6 @@
                                     int              *fd2,
                                     dbus_bool_t       blocking,
                                     DBusError        *error);
-dbus_bool_t _dbus_close            (int               fd,
-                                    DBusError        *error);
 
 void        _dbus_print_backtrace  (void);
 
@@ -322,10 +349,8 @@
 void _dbus_set_signal_handler (int               sig,
                                DBusSignalHandler handler);
 
-dbus_bool_t _dbus_file_exists     (const char *file);
 dbus_bool_t _dbus_user_at_console (const char *username,
                                    DBusError  *error);
-const char* _dbus_get_tmpdir      (void);
 
 /* Define DBUS_VA_COPY() to do the right thing for copying va_list variables. 
  * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy. 

Index: dbus-transport-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport-unix.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- dbus-transport-unix.c	14 Sep 2006 13:53:16 -0000	1.51
+++ dbus-transport-unix.c	16 Sep 2006 15:34:34 -0000	1.52
@@ -250,8 +250,8 @@
 
   _dbus_auth_get_buffer (transport->auth, &buffer);
   
-  bytes_read = _dbus_read (unix_transport->fd,
-                           buffer, unix_transport->max_bytes_read_per_iteration);
+  bytes_read = _dbus_read_socket (unix_transport->fd,
+                                  buffer, unix_transport->max_bytes_read_per_iteration);
 
   _dbus_auth_return_buffer (transport->auth, buffer,
                             bytes_read > 0 ? bytes_read : 0);
@@ -305,9 +305,9 @@
                                      &buffer))
     return FALSE;
   
-  bytes_written = _dbus_write (unix_transport->fd,
-                               buffer,
-                               0, _dbus_string_get_length (buffer));
+  bytes_written = _dbus_write_socket (unix_transport->fd,
+                                      buffer,
+                                      0, _dbus_string_get_length (buffer));
 
   if (bytes_written > 0)
     {
@@ -556,10 +556,10 @@
 #endif
           
           bytes_written =
-            _dbus_write (unix_transport->fd,
-                         &unix_transport->encoded_outgoing,
-                         unix_transport->message_bytes_written,
-                         total_bytes_to_write - unix_transport->message_bytes_written);
+            _dbus_write_socket (unix_transport->fd,
+                                &unix_transport->encoded_outgoing,
+                                unix_transport->message_bytes_written,
+                                total_bytes_to_write - unix_transport->message_bytes_written);
         }
       else
         {
@@ -573,21 +573,21 @@
           if (unix_transport->message_bytes_written < header_len)
             {
               bytes_written =
-                _dbus_write_two (unix_transport->fd,
-                                 header,
-                                 unix_transport->message_bytes_written,
-                                 header_len - unix_transport->message_bytes_written,
-                                 body,
-                                 0, body_len);
+                _dbus_write_socket_two (unix_transport->fd,
+                                        header,
+                                        unix_transport->message_bytes_written,
+                                        header_len - unix_transport->message_bytes_written,
+                                        body,
+                                        0, body_len);
             }
           else
             {
               bytes_written =
-                _dbus_write (unix_transport->fd,
-                             body,
-                             (unix_transport->message_bytes_written - header_len),
-                             body_len -
-                             (unix_transport->message_bytes_written - header_len));
+                _dbus_write_socket (unix_transport->fd,
+                                    body,
+                                    (unix_transport->message_bytes_written - header_len),
+                                    body_len -
+                                    (unix_transport->message_bytes_written - header_len));
             }
         }
 
@@ -682,9 +682,9 @@
       if (_dbus_string_get_length (&unix_transport->encoded_incoming) > 0)
         bytes_read = _dbus_string_get_length (&unix_transport->encoded_incoming);
       else
-        bytes_read = _dbus_read (unix_transport->fd,
-                                 &unix_transport->encoded_incoming,
-                                 unix_transport->max_bytes_read_per_iteration);
+        bytes_read = _dbus_read_socket (unix_transport->fd,
+                                        &unix_transport->encoded_incoming,
+                                        unix_transport->max_bytes_read_per_iteration);
 
       _dbus_assert (_dbus_string_get_length (&unix_transport->encoded_incoming) ==
                     bytes_read);
@@ -719,8 +719,8 @@
       _dbus_message_loader_get_buffer (transport->loader,
                                        &buffer);
       
-      bytes_read = _dbus_read (unix_transport->fd,
-                               buffer, unix_transport->max_bytes_read_per_iteration);
+      bytes_read = _dbus_read_socket (unix_transport->fd,
+                                      buffer, unix_transport->max_bytes_read_per_iteration);
       
       _dbus_message_loader_return_buffer (transport->loader,
                                           buffer,
@@ -882,7 +882,7 @@
   
   free_watches (transport);
   
-  _dbus_close (unix_transport->fd, NULL);
+  _dbus_close_socket (unix_transport->fd, NULL);
   unix_transport->fd = -1;
 }
 
@@ -1247,7 +1247,7 @@
   return transport;
 
  failed_1:
-  _dbus_close (fd, NULL);
+  _dbus_close_socket (fd, NULL);
  failed_0:
   _dbus_string_free (&address);
   return NULL;
@@ -1307,7 +1307,7 @@
   if (transport == NULL)
     {
       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-      _dbus_close (fd, NULL);
+      _dbus_close_socket (fd, NULL);
       _dbus_string_free (&address);
       fd = -1;
     }



More information about the dbus-commit mailing list