From 1708094c0e00ab433bb0a51981f8b77d24aee256 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 9 Apr 2003 20:31:21 +0000 Subject: 2003-04-09 Havoc Pennington * dbus/dbus-bus.c (dbus_bus_register): fix up error handling and a memory leak * bus/dispatch.c (check_service_activated): fix bug in test * dbus/dbus-mainloop.c (check_timeout): fix this up * dbus/dbus-internals.c (_dbus_verbose_real): include PID in verbose output so we can sort out output from different processes, e.g. in the activation case. --- dbus/dbus-bus.c | 35 +++++++++++++++++++++-------------- dbus/dbus-connection.c | 16 +++++++++++++--- dbus/dbus-internals.c | 6 +++++- 3 files changed, 39 insertions(+), 18 deletions(-) (limited to 'dbus') diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c index 74703866..e7b4c06e 100644 --- a/dbus/dbus-bus.c +++ b/dbus/dbus-bus.c @@ -428,8 +428,11 @@ dbus_bus_register (DBusConnection *connection, DBusMessage *message, *reply; char *name; BusData *bd; - + dbus_bool_t retval; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + retval = FALSE; bd = ensure_bus_data (connection); if (bd == NULL) @@ -461,22 +464,26 @@ dbus_bus_register (DBusConnection *connection, dbus_message_unref (message); if (reply == NULL) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - return FALSE; - } + goto out; + else if (dbus_set_error_from_message (error, reply)) + goto out; + else if (!dbus_message_get_args (reply, error, + DBUS_TYPE_STRING, &name, + 0)) + goto out; + + bd->base_service = name; - if (!dbus_message_get_args (reply, error, - DBUS_TYPE_STRING, &name, - 0)) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - return FALSE; - } + retval = TRUE; + + out: + if (reply) + dbus_message_unref (reply); - bd->base_service = name; + if (!retval) + _DBUS_ASSERT_ERROR_IS_SET (error); - return TRUE; + return retval; } diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index d92268ba..60c075fe 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -1461,8 +1461,9 @@ dbus_connection_send_with_reply_and_block (DBusConnection *connection, end_tv_sec += end_tv_usec / _DBUS_USEC_PER_SECOND; end_tv_usec = end_tv_usec % _DBUS_USEC_PER_SECOND; - _dbus_verbose ("will block %d milliseconds from %ld sec %ld usec to %ld sec %ld usec\n", + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): will block %d milliseconds for reply serial %d from %ld sec %ld usec to %ld sec %ld usec\n", timeout_milliseconds, + client_serial, start_tv_sec, start_tv_usec, end_tv_sec, end_tv_usec); @@ -1489,6 +1490,10 @@ dbus_connection_send_with_reply_and_block (DBusConnection *connection, if (reply != NULL) { dbus_mutex_unlock (connection->mutex); + + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): got reply %s\n", + dbus_message_get_name (reply)); + return reply; } } @@ -1504,7 +1509,7 @@ dbus_connection_send_with_reply_and_block (DBusConnection *connection, { timeout_milliseconds = (end_tv_sec - tv_sec) * 1000 + (end_tv_usec - tv_usec) / 1000; - _dbus_verbose ("%d milliseconds remain\n", timeout_milliseconds); + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): %d milliseconds remain\n", timeout_milliseconds); _dbus_assert (timeout_milliseconds >= 0); if (status == DBUS_DISPATCH_NEED_MEMORY) @@ -1513,6 +1518,8 @@ dbus_connection_send_with_reply_and_block (DBusConnection *connection, * we may already have a reply in the buffer and just can't process * it. */ + _dbus_verbose ("dbus_connection_send_with_reply_and_block() waiting for more memory\n"); + if (timeout_milliseconds < 100) ; /* just busy loop */ else if (timeout_milliseconds <= 1000) @@ -1531,12 +1538,15 @@ dbus_connection_send_with_reply_and_block (DBusConnection *connection, goto recheck_status; } + + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): Waited %ld milliseconds and got no reply\n", + (tv_sec - start_tv_sec) * 1000 + (tv_usec - start_tv_usec) / 1000); if (dbus_connection_get_is_connected (connection)) dbus_set_error (error, DBUS_ERROR_NO_REPLY, "Message did not receive a reply"); else dbus_set_error (error, DBUS_ERROR_DISCONNECTED, "Disconnected prior to receiving a reply"); - + dbus_mutex_unlock (connection->mutex); return NULL; diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index de98c1fc..6a662e5d 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -189,7 +189,8 @@ _dbus_verbose_real (const char *format, va_list args; static dbus_bool_t verbose = TRUE; static dbus_bool_t initted = FALSE; - + static unsigned long pid; + /* things are written a bit oddly here so that * in the non-verbose case we just have the one * conditional and return immediately. @@ -200,10 +201,13 @@ _dbus_verbose_real (const char *format, if (!initted) { verbose = _dbus_getenv ("DBUS_VERBOSE") != NULL; + pid = _dbus_getpid (); initted = TRUE; if (!verbose) return; } + + fprintf (stderr, "%lu: ", pid); va_start (args, format); vfprintf (stderr, format, args); -- cgit