2006-08-29 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Wed, 30 Aug 2006 01:27:44 +0000 (01:27 +0000)
committerHavoc Pennington <hp@redhat.com>
Wed, 30 Aug 2006 01:27:44 +0000 (01:27 +0000)
* test/test-service.c (path_message_func): fix lack of return value

* dbus/dbus-sysdeps.c (_dbus_printf_string_upper_bound): fix
formatting, remove #ifdef, and fix docs. #ifdef doesn't make
any more sense than on anything else in this file.
(_dbus_get_tmpdir): add const to return value, and keep the
results of the various getenv around in a static variable.

ChangeLog
dbus/dbus-sysdeps.c
dbus/dbus-sysdeps.h
test/test-service.c

index 203584c..5fde3c1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2006-08-29  Havoc Pennington  <hp@redhat.com>
 
+       * test/test-service.c (path_message_func): fix lack of return value
+
+       * dbus/dbus-sysdeps.c (_dbus_printf_string_upper_bound): fix
+       formatting, remove #ifdef, and fix docs. #ifdef doesn't make
+       any more sense than on anything else in this file.
+       (_dbus_get_tmpdir): add const to return value, and keep the
+       results of the various getenv around in a static variable.
+
+2006-08-29  Havoc Pennington  <hp@redhat.com>
+
        * dbus/dbus-sysdeps-util.c, dbus/dbus-sysdeps-util-unix.c: change
        from Ralf Habacker to move UNIX-specific sysdeps into a separate file.
 
index 0a97a1d..3dfe0e8 100644 (file)
@@ -2987,47 +2987,58 @@ _dbus_full_duplex_pipe (int        *fd1,
 }
 
 
-#ifndef DBUS_WIN
 /**
- * Measure the message length without terminating nul
+ * Measure the length of the given format string and arguments,
+ * not including the terminating nul.
+ *
+ * @param format a printf-style format string
+ * @param args arguments for the format string
+ * @returns length of the given format string and args
  */
-int _dbus_printf_string_upper_bound (const char *format,
-                                     va_list args)
+int
+_dbus_printf_string_upper_bound (const char *format,
+                                 va_list     args)
 {
   char c;
   return vsnprintf (&c, 1, format, args);
 }
-#endif
-
-
 
 /**
  * Gets the temporary files directory by inspecting the environment variables 
  * TMPDIR, TMP, and TEMP in that order. If none of those are set "/tmp" is returned
  *
- * @returns char* - location of temp directory
+ * @returns location of temp directory
  */
-char*
+const char*
 _dbus_get_tmpdir(void)
 {
-  char* tmpdir;
+  static const char* tmpdir = NULL;
 
-  tmpdir = getenv("TMPDIR");
-  if (tmpdir) {
-     return tmpdir;
-  }
+  if (tmpdir == NULL)
+    {
+      /* TMPDIR is what glibc uses, then
+       * glibc falls back to the P_tmpdir macro which
+       * just expands to "/tmp"
+       */
+      if (tmpdir == NULL)
+        tmpdir = getenv("TMPDIR");
 
-  tmpdir = getenv("TMP");
-  if (tmpdir) {
-     return tmpdir;
-  }
-  
-  tmpdir = getenv("TEMP");
-  if (tmpdir) {
-     return tmpdir;
-  }
+      /* These two env variables are probably
+       * broken, but maybe some OS uses them?
+       */
+      if (tmpdir == NULL)
+        tmpdir = getenv("TMP");
+      if (tmpdir == NULL)
+        tmpdir = getenv("TEMP");
 
-  return "/tmp";
+      /* And this is the sane fallback. */
+      if (tmpdir == NULL)
+        tmpdir = "/tmp";
+    }
+  
+  _dbus_assert(tmpdir != NULL);
+  
+  return tmpdir;
 }
 
 /** @} end of sysdeps */
index 1df9986..f180366 100644 (file)
@@ -323,7 +323,7 @@ void _dbus_set_signal_handler (int               sig,
 dbus_bool_t _dbus_file_exists     (const char *file);
 dbus_bool_t _dbus_user_at_console (const char *username,
                                    DBusError  *error);
-char* _dbus_get_tmpdir(void);
+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 ed47a50..6a633b7 100644 (file)
@@ -293,6 +293,8 @@ path_message_func (DBusConnection  *connection,
         
         if (!dbus_connection_send (connection, reply, NULL))
           die ("No memory");
+
+        return DBUS_HANDLER_RESULT_HANDLED;
     }
   else
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;