summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--bus/driver.c64
-rw-r--r--dbus/dbus-sysdeps.c20
-rw-r--r--dbus/dbus-sysdeps.h3
4 files changed, 82 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 54168e9d..adbd7bba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2003-01-21 Havoc Pennington <hp@pobox.com>
+
+ (patch untested because can't compile)
+
+ * bus/driver.c (create_unique_client_name): make this function
+ never recycle client names. Also, caller should initialize
+ the DBusString.
+
+ * dbus/dbus-sysdeps.c (_dbus_get_current_time): new function
+
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-marshal.c: (_dbus_marshal_double),
diff --git a/bus/driver.c b/bus/driver.c
index d24cb77f..eda09af4 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -36,34 +36,62 @@ static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection,
DBusMessage *hello_message);
static dbus_bool_t
-create_unique_client_name (const char *name, DBusString *str)
+create_unique_client_name (const char *name,
+ DBusString *str)
{
- int i, len;
-
- if (!_dbus_string_init (str, _DBUS_INT_MAX))
- return FALSE;
+ /* We never want to use the same unique client name twice, because
+ * we want to guarantee that if you send a message to a given unique
+ * name, you always get the same application. So we use two numbers
+ * for INT_MAX * INT_MAX combinations, should be pretty safe against
+ * wraparound.
+ */
+ static int next_major_number = 0;
+ static int next_minor_number = 0;
+ int len;
if (!_dbus_string_append (str, name))
return FALSE;
len = _dbus_string_get_length (str);
- i = 0;
- while (1)
+ while (TRUE)
{
- if (!_dbus_string_append_int (str, i))
- {
- _dbus_string_free (str);
- return FALSE;
- }
+ /* start out with 1-0, go to 1-1, 1-2, 1-3,
+ * up to 1-MAXINT, then 2-0, 2-1, etc.
+ */
+ if (next_minor_number <= 0)
+ {
+ next_major_number += 1;
+ next_minor_number = 0;
+ if (next_major_number <= 0)
+ _dbus_assert_not_reached ("INT_MAX * INT_MAX clients were added");
+ }
+
+ _dbus_assert (next_major_number > 0);
+ _dbus_assert (next_minor_number >= 0);
+
+ /* appname:MAJOR-MINOR */
+
+ if (!_dbus_string_append (str, ":"))
+ return FALSE;
+
+ if (!_dbus_string_append_int (str, next_major_number))
+ return FALSE;
+
+ if (!_dbus_string_append (str, "-"))
+ return FALSE;
+
+ if (!_dbus_string_append_int (str, next_minor_number))
+ return FALSE;
+
+ next_minor_number += 1;
/* Check if a client with the name exists */
if (bus_service_lookup (str, FALSE) == NULL)
break;
+ /* drop the number again, try the next one. */
_dbus_string_set_length (str, len);
-
- i++;
}
return TRUE;
@@ -87,8 +115,14 @@ bus_driver_handle_hello_message (DBusConnection *connection,
if (result != DBUS_RESULT_SUCCESS)
return FALSE;
- if (!create_unique_client_name (name, &unique_name))
+ if (!_dbus_string_init (&unique_name, _DBUS_INT_MAX))
return FALSE;
+
+ if (!create_unique_client_name (name, &unique_name))
+ {
+ _dbus_string_free (&unique_name);
+ return FALSE;
+ }
/* Create the service */
service = bus_service_lookup (&unique_name, TRUE);
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c
index a4074828..c91a06ff 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -983,4 +983,24 @@ _dbus_sleep_milliseconds (int milliseconds)
#endif
}
+/**
+ * Get current time, as in gettimeofday().
+ *
+ * @param tv_sec return location for number of seconds
+ * @param tv_usec return location for number of microseconds (thousandths)
+ */
+void
+_dbus_get_current_time (long *tv_sec,
+ long *tv_usec)
+{
+ struct timeval t;
+
+ gettimeofday (&t, NULL);
+
+ if (tv_sec)
+ *tv_sec = t.tv_sec;
+ if (tv_usec)
+ *tv_usec = t.tv_usec;
+}
+
/** @} end of sysdeps */
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index c76c691a..5b9a0c09 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -118,6 +118,9 @@ int _dbus_poll (DBusPollFD *fds,
void _dbus_sleep_milliseconds (int milliseconds);
+void _dbus_get_current_time (long *tv_sec,
+ long *tv_usec);
+
DBUS_END_DECLS;
#endif /* DBUS_SYSDEPS_H */