dbus/dbus dbus-sysdeps-unix.c,1.4,1.5 dbus-sysdeps.h,1.57,1.58

Havoc Pennington hp at kemper.freedesktop.org
Sat Sep 16 08:49:29 PDT 2006


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

Modified Files:
	dbus-sysdeps-unix.c dbus-sysdeps.h 
Log Message:
2006-09-16  Havoc Pennington  <hp at redhat.com>

	* dbus/dbus-sysdeps-unix.c (_dbus_open_tcp_socket) 
	(_dbus_open_unix_socket, _dbus_open_socket): change API for 
	_dbus_open_socket so the domain/type/protocol from system headers
	are not required. This is kind of pointless though unless we move
	part of _dbus_connect_tcp_socket into sysdeps.c instead of
	sysdeps-unix.c, which would mean adding a wrapper around
	bind/listen/etc.
	Also, add DBusError to the socket-opening functions so they 
	don't require use of errno.



Index: dbus-sysdeps-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps-unix.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dbus-sysdeps-unix.c	16 Sep 2006 15:34:34 -0000	1.4
+++ dbus-sysdeps-unix.c	16 Sep 2006 15:49:27 -0000	1.5
@@ -77,14 +77,40 @@
  * @{
  */
 
-dbus_bool_t
+static dbus_bool_t
 _dbus_open_socket (int              *fd,
                    int               domain,
                    int               type,
-                   int               protocol)
+                   int               protocol,
+                   DBusError        *error)
 {
   *fd = socket (domain, type, protocol);
-  return fd >= 0;
+  if (fd >= 0)
+    {
+      return TRUE;
+    }
+  else
+    {
+      dbus_set_error(error,
+                     _dbus_error_from_errno (errno),
+                     "Failed to open socket: %s",
+                     _dbus_strerror (errno));
+      return FALSE;
+    }
+}
+
+dbus_bool_t
+_dbus_open_tcp_socket (int              *fd,
+                       DBusError        *error)
+{
+  return _dbus_open_socket(fd, AF_INET, SOCK_STREAM, 0, error);
+}
+
+dbus_bool_t
+_dbus_open_unix_socket (int              *fd,
+                        DBusError        *error)
+{
+  return _dbus_open_socket(fd, PF_UNIX, SOCK_STREAM, 0, error);
 }
 
 dbus_bool_t 
@@ -356,15 +382,12 @@
                  path, abstract);
   
   
-  if (!_dbus_open_socket (&fd, PF_UNIX, SOCK_STREAM, 0))
+  if (!_dbus_open_unix_socket (&fd, error))
     {
-      dbus_set_error (error,
-                      _dbus_error_from_errno (errno),
-                      "Failed to create socket: %s",
-                      _dbus_strerror (errno)); 
-      
+      _DBUS_ASSERT_ERROR_IS_SET(error);
       return -1;
     }
+  _DBUS_ASSERT_ERROR_IS_CLEAR(error);
 
   _DBUS_ZERO (addr);
   addr.sun_family = AF_UNIX;
@@ -490,13 +513,12 @@
   _dbus_verbose ("listening on unix socket %s abstract=%d\n",
                  path, abstract);
   
-  if (!_dbus_open_socket (&listen_fd, PF_UNIX, SOCK_STREAM, 0))
+  if (!_dbus_open_unix_socket (&listen_fd, error))
     {
-      dbus_set_error (error, _dbus_error_from_errno (errno),
-                      "Failed to create socket \"%s\": %s",
-                      path, _dbus_strerror (errno));
+      _DBUS_ASSERT_ERROR_IS_SET(error);
       return -1;
     }
+  _DBUS_ASSERT_ERROR_IS_CLEAR(error);
 
   _DBUS_ZERO (addr);
   addr.sun_family = AF_UNIX;
@@ -626,16 +648,14 @@
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
  
   
-  if (!_dbus_open_socket (&fd, AF_INET, SOCK_STREAM, 0))
+  if (!_dbus_open_tcp_socket (&fd, error))
     {
-      dbus_set_error (error,
-                      _dbus_error_from_errno (errno),
-                      "Failed to create socket: %s",
-                      _dbus_strerror (errno)); 
+      _DBUS_ASSERT_ERROR_IS_SET(error);
       
       return -1;
     }
-
+  _DBUS_ASSERT_ERROR_IS_CLEAR(error);
+      
   if (host == NULL)
     host = "localhost";
 
@@ -704,13 +724,12 @@
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   
   
-  if (!_dbus_open_socket (&listen_fd, AF_INET, SOCK_STREAM, 0))
+  if (!_dbus_open_tcp_socket (&listen_fd, error))
     {
-      dbus_set_error (error, _dbus_error_from_errno (errno),
-                      "Failed to create socket \"%s:%d\": %s",
-                      host, port, _dbus_strerror (errno));
+      _DBUS_ASSERT_ERROR_IS_SET(error);
       return -1;
     }
+  _DBUS_ASSERT_ERROR_IS_CLEAR(error);
 
   he = gethostbyname (host);
   if (he == NULL) 

Index: dbus-sysdeps.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.h,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- dbus-sysdeps.h	16 Sep 2006 15:34:34 -0000	1.57
+++ dbus-sysdeps.h	16 Sep 2006 15:49:27 -0000	1.58
@@ -98,10 +98,10 @@
  * 
  */
 
-dbus_bool_t _dbus_open_socket      (int              *fd,
-                                    int               domain, 
-                                    int               type, 
-                                    int               protocol);
+dbus_bool_t _dbus_open_tcp_socket  (int              *fd,
+                                    DBusError        *error);
+dbus_bool_t _dbus_open_unix_socket (int              *fd,
+                                    DBusError        *error);
 dbus_bool_t _dbus_close_socket     (int               fd,
                                     DBusError        *error);
 int         _dbus_read_socket      (int               fd,



More information about the dbus-commit mailing list