From a9eaac78c30a9a2728384b88eb6667504b758e24 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 7 Jan 2009 10:02:12 -0500 Subject: [PATCH] Bug 19441 - Don't send reply when none is requested It's normally harmless, but unrequested replies now get noisly denied by the system bus. --- dbus/dbus-gobject.c | 42 ++++++++++++++++++++++++------------------ 1 files changed, 24 insertions(+), 18 deletions(-) diff --git a/dbus/dbus-gobject.c b/dbus/dbus-gobject.c index 572fafd..107dd10 100644 --- a/dbus/dbus-gobject.c +++ b/dbus/dbus-gobject.c @@ -1117,7 +1117,7 @@ invoke_object_method (GObject *object, DBusConnection *connection, DBusMessage *message) { - gboolean had_error, call_only; + gboolean had_error, use_thread, send_reply; GError *gerror; GValueArray *value_array; GValue return_value = {0,}; @@ -1128,7 +1128,7 @@ invoke_object_method (GObject *object, int out_param_count; int out_param_pos, out_param_gvalue_pos; DBusHandlerResult result; - DBusMessage *reply; + DBusMessage *reply = NULL; gboolean have_retval; gboolean retval_signals_error; gboolean retval_is_synthetic; @@ -1140,10 +1140,8 @@ invoke_object_method (GObject *object, /* Determine whether or not this method should be invoked in a new thread */ - if (strcmp (string_table_lookup (get_method_data (object_info, method), 2), "A") == 0) - call_only = TRUE; - else - call_only = FALSE; + use_thread = strcmp (string_table_lookup (get_method_data (object_info, method), 2), "A") == 0; + send_reply = !dbus_message_get_no_reply (message); have_retval = FALSE; retval_signals_error = FALSE; @@ -1194,7 +1192,7 @@ invoke_object_method (GObject *object, g_value_init (g_value_array_get_nth (value_array, 0), G_TYPE_OBJECT); g_value_set_object (g_value_array_get_nth (value_array, 0), object); - if (call_only) + if (use_thread) { GValue context_value = {0,}; DBusGMethodInvocation *context; @@ -1340,7 +1338,7 @@ invoke_object_method (GObject *object, value_array->n_values, value_array->values, NULL, method->function); - if (call_only) + if (use_thread) { result = DBUS_HANDLER_RESULT_HANDLED; goto done; @@ -1354,17 +1352,25 @@ invoke_object_method (GObject *object, { DBusMessageIter iter; - reply = dbus_message_new_method_return (message); - if (reply == NULL) - goto nomem; + /* Careful here - there are two major cases in this section of the code. + * If send_reply is TRUE, we're constructing a dbus message and freeing + * the return values. If it's FALSE, then we just need to free the + * values. + */ + if (send_reply) + { + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto nomem; - /* Append output arguments to reply */ - dbus_message_iter_init_append (reply, &iter); + /* Append output arguments to reply */ + dbus_message_iter_init_append (reply, &iter); + } /* First, append the return value, unless it's synthetic */ if (have_retval && !retval_is_synthetic) - { - if (!_dbus_gvalue_marshal (&iter, &return_value)) + { + if (send_reply && !_dbus_gvalue_marshal (&iter, &return_value)) goto nomem; if (!retval_is_constant) g_value_unset (&return_value); @@ -1416,7 +1422,7 @@ invoke_object_method (GObject *object, out_param_gvalue_pos++; } - if (!_dbus_gvalue_marshal (&iter, &gvalue)) + if (send_reply && !_dbus_gvalue_marshal (&iter, &gvalue)) goto nomem; /* Here we actually free the allocated value; we * took ownership of it with _dbus_gvalue_take, unless @@ -1426,7 +1432,7 @@ invoke_object_method (GObject *object, g_value_unset (&gvalue); } } - else + else if (send_reply) reply = gerror_to_dbus_error_message (object_info, message, gerror); if (reply) @@ -1438,7 +1444,7 @@ invoke_object_method (GObject *object, result = DBUS_HANDLER_RESULT_HANDLED; done: g_free (in_signature); - if (!call_only) + if (!use_thread) { g_array_free (out_param_values, TRUE); g_value_array_free (out_param_gvalues); -- 1.6.0.6