From 54a0f22c7ddaaa86deb2bde6734fb2448300914c Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Fri, 7 May 2021 11:13:26 +0200 Subject: [PATCH] dbus-daemon: send signals on connection overflow Change-Id: I4f0e78fe9ad8c63da7256f2dadae2029eb534004 --- bus/connection.c | 8 ++++++++ bus/connection.h | 1 + bus/dispatch.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/bus/connection.c b/bus/connection.c index 78948c6..15aea6e 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -2728,6 +2728,14 @@ bus_transaction_execute_and_free (BusTransaction *transaction) transaction_free (transaction); } +DBusList * +bus_transaction_copy_connections (BusTransaction *transaction) +{ + DBusList *result = NULL; + _dbus_list_copy (&transaction->connections, &result); + return result; +} + static void bus_connection_remove_transactions (DBusConnection *connection) { diff --git a/bus/connection.h b/bus/connection.h index acaee15..6da99a3 100644 --- a/bus/connection.h +++ b/bus/connection.h @@ -173,6 +173,7 @@ dbus_bool_t bus_transaction_send_error_reply (BusTransaction * DBusMessage *in_reply_to); void bus_transaction_cancel_and_free (BusTransaction *transaction); void bus_transaction_execute_and_free (BusTransaction *transaction); +DBusList * bus_transaction_copy_connections (BusTransaction *transaction); dbus_bool_t bus_transaction_add_cancel_hook (BusTransaction *transaction, BusTransactionCancelFunction cancel_function, void *data, diff --git a/bus/dispatch.c b/bus/dispatch.c index d829296..50bb78b 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -314,11 +314,17 @@ bus_dispatch_matches (BusTransaction *transaction, dest = link->data; + link = _dbus_list_get_next_link (&recipients, link); + + if (_dbus_connection_is_overflowed (dest) + && dbus_message_is_signal (message, + DBUS_INTERFACE_TIZEN, + DBUS_TIZEN_CONNECTION_OVERFLOW_SIGNAL)) + continue; + if (!send_one_message (dest, context, sender, addressed_recipient, message, transaction, &tmp_error)) break; - - link = _dbus_list_get_next_link (&recipients, link); } _dbus_list_clear (&recipients); @@ -332,6 +338,35 @@ bus_dispatch_matches (BusTransaction *transaction, return BUS_RESULT_TRUE; } +static void +bus_check_connection_overflow (BusContext *context, + DBusList *connections) +{ + BusTransaction *transaction; + DBusConnection *recipient; + DBusError error; + + transaction = bus_transaction_new (context); + if (transaction == NULL) + return; + + dbus_error_init (&error); + + while ((recipient = _dbus_list_pop_first (&connections))) + if (_dbus_connection_is_overflowed (recipient)) + { + if (!bus_driver_send_connection_overflow (recipient, transaction, &error)) + { + bus_transaction_cancel_and_free (transaction); + transaction = NULL; + break; + } + } + + if (transaction != NULL) + bus_transaction_execute_and_free (transaction); +} + static DBusHandlerResult bus_dispatch (DBusConnection *connection, DBusMessage *message) @@ -700,7 +735,11 @@ bus_dispatch (DBusConnection *connection, if (transaction != NULL) { + DBusList *connections_copy = bus_transaction_copy_connections (transaction); + bus_transaction_execute_and_free (transaction); + + bus_check_connection_overflow (context, connections_copy); } dbus_connection_unref (connection); -- 2.7.4