2003-06-09 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Mon, 9 Jun 2003 22:09:34 +0000 (22:09 +0000)
committerHavoc Pennington <hp@redhat.com>
Mon, 9 Jun 2003 22:09:34 +0000 (22:09 +0000)
* dbus/dbus-sysdeps.c (_dbus_listen_unix_socket): don't use
SUN_LEN, it breaks abstract socket usage

* dbus/dbus-internals.c (_dbus_verbose_real): only print PID at
starts of lines.

ChangeLog
dbus/dbus-internals.c
dbus/dbus-sysdeps.c

index 7874185..75a8235 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-06-09  Havoc Pennington  <hp@redhat.com>
+
+       * dbus/dbus-sysdeps.c (_dbus_listen_unix_socket): don't use
+       SUN_LEN, it breaks abstract socket usage
+
+       * dbus/dbus-internals.c (_dbus_verbose_real): only print PID at
+       starts of lines.
+
 2003-06-04  Havoc Pennington  <hp@pobox.com>
 
        * dbus/dbus-server.c (dbus_server_listen): allow abstract sockets
index 6a091e6..6e7f9e1 100644 (file)
@@ -190,6 +190,7 @@ _dbus_verbose_real (const char *format,
 {
   va_list args;
   static dbus_bool_t verbose = TRUE;
+  static dbus_bool_t need_pid = TRUE;
   
   /* things are written a bit oddly here so that
    * in the non-verbose case we just have the one
@@ -206,7 +207,18 @@ _dbus_verbose_real (const char *format,
         return;
     }
 
-  fprintf (stderr, "%lu: ", _dbus_getpid ());
+  if (need_pid)
+    {
+      int len;
+      
+      fprintf (stderr, "%lu: ", _dbus_getpid ());
+
+      len = strlen (format);
+      if (format[len-1] == '\n')
+        need_pid = TRUE;
+      else
+        need_pid = FALSE;
+    }
   
   va_start (args, format);
   vfprintf (stderr, format, args);
index 35900d7..be867a9 100644 (file)
 #define O_BINARY 0
 #endif
 
-#ifndef SUN_LEN
-/* This system is not POSIX.1g.         */
-#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path)  \
-       + strlen ((ptr)->sun_path))
-#endif
-
 /**
  * @addtogroup DBusInternalsUtils
  * @{
@@ -392,6 +386,9 @@ _dbus_connect_unix_socket (const char     *path,
   struct sockaddr_un addr;  
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+  _dbus_verbose ("connecting to unix socket %s abstract=%d\n",
+                 path, abstract);
   
   fd = socket (PF_UNIX, SOCK_STREAM, 0);
   
@@ -411,14 +408,18 @@ _dbus_connect_unix_socket (const char     *path,
   if (abstract)
     {
 #ifdef HAVE_ABSTRACT_SOCKETS
+      /* remember that abstract names aren't nul-terminated so we rely
+       * on sun_path being filled in with zeroes above.
+       */
       addr.sun_path[0] = '\0'; /* this is what says "use abstract" */
       strncpy (&addr.sun_path[1], path, _DBUS_MAX_SUN_PATH_LENGTH - 2);
+      /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
 #else /* HAVE_ABSTRACT_SOCKETS */
       dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
                       "Operating system does not support abstract socket namespace\n");
       close (fd);
       return -1;
-#endif /* ! HAVE_ABSTRACT_SOCKETS */      
+#endif /* ! HAVE_ABSTRACT_SOCKETS */
     }
   else
     {
@@ -475,6 +476,9 @@ _dbus_listen_unix_socket (const char     *path,
   struct sockaddr_un addr;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+  _dbus_verbose ("listening on unix socket %s abstract=%d\n",
+                 path, abstract);
   
   listen_fd = socket (PF_UNIX, SOCK_STREAM, 0);
   
@@ -492,8 +496,12 @@ _dbus_listen_unix_socket (const char     *path,
   if (abstract)
     {
 #ifdef HAVE_ABSTRACT_SOCKETS
+      /* remember that abstract names aren't nul-terminated so we rely
+       * on sun_path being filled in with zeroes above.
+       */
       addr.sun_path[0] = '\0'; /* this is what says "use abstract" */
       strncpy (&addr.sun_path[1], path, _DBUS_MAX_SUN_PATH_LENGTH - 2);
+      /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
 #else /* HAVE_ABSTRACT_SOCKETS */
       dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
                       "Operating system does not support abstract socket namespace\n");
@@ -524,7 +532,7 @@ _dbus_listen_unix_socket (const char     *path,
       strncpy (addr.sun_path, path, _DBUS_MAX_SUN_PATH_LENGTH - 1);
     }
   
-  if (bind (listen_fd, (struct sockaddr*) &addr, SUN_LEN (&addr)) < 0)
+  if (bind (listen_fd, (struct sockaddr*) &addr, sizeof (addr)) < 0)
     {
       dbus_set_error (error, _dbus_error_from_errno (errno),
                       "Failed to bind socket \"%s\": %s",
@@ -548,7 +556,7 @@ _dbus_listen_unix_socket (const char     *path,
       close (listen_fd);
       return -1;
     }
-
+  
   /* Try opening up the permissions, but if we can't, just go ahead
    * and continue, maybe it will be good enough.
    */