summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-connection.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-09-22 01:29:14 +0000
committerHavoc Pennington <hp@redhat.com>2003-09-22 01:29:14 +0000
commit25cb861980003f81eade8707bfa1a61c9ece1779 (patch)
tree78c225527a36193c981b4525f7493d5dc552e2ee /dbus/dbus-connection.c
parenta683a80c409cc4f2e57ba6a3e60d52f91b8657d0 (diff)
2003-09-21 Havoc Pennington <hp@pobox.com>
* dbus/dbus-bus.c (dbus_bus_get): set exit_on_disconnect to TRUE by default for message bus connections. * dbus/dbus-connection.c (dbus_connection_dispatch): exit if exit_on_disconnect flag is set and we process the disconnected signal. (dbus_connection_set_exit_on_disconnect): new function
Diffstat (limited to 'dbus/dbus-connection.c')
-rw-r--r--dbus/dbus-connection.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index b55f270c..ed7d57d0 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -206,6 +206,8 @@ struct DBusConnection
* for the global linked list mempool lock
*/
DBusObjectTree *objects; /**< Object path handlers registered with this connection */
+
+ unsigned int exit_on_disconnect : 1; /**< If #TRUE, exit after handling disconnect signal */
};
static void _dbus_connection_remove_timeout_locked (DBusConnection *connection,
@@ -906,6 +908,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
connection->filter_list = NULL;
connection->last_dispatch_status = DBUS_DISPATCH_COMPLETE; /* so we're notified first time there's data */
connection->objects = objects;
+ connection->exit_on_disconnect = FALSE;
_dbus_data_slot_list_init (&connection->slot_list);
@@ -1356,6 +1359,30 @@ dbus_connection_get_is_authenticated (DBusConnection *connection)
return res;
}
+/**
+ * Set whether _exit() should be called when the connection receives a
+ * disconnect signal. The call to _exit() comes after any handlers for
+ * the disconnect signal run; handlers can cancel the exit by calling
+ * this function.
+ *
+ * By default, exit_on_disconnect is #FALSE; but for message bus
+ * connections returned from dbus_bus_get() it will be toggled on
+ * by default.
+ *
+ * @param connection the connection
+ * @param exit_on_disconnect #TRUE if _exit() should be called after a disconnect signal
+ */
+void
+dbus_connection_set_exit_on_disconnect (DBusConnection *connection,
+ dbus_bool_t exit_on_disconnect)
+{
+ _dbus_return_if_fail (connection != NULL);
+
+ CONNECTION_LOCK (connection);
+ connection->exit_on_disconnect = exit_on_disconnect != FALSE;
+ CONNECTION_UNLOCK (connection);
+}
+
static DBusPreallocatedSend*
_dbus_connection_preallocate_send_unlocked (DBusConnection *connection)
{
@@ -2616,6 +2643,17 @@ dbus_connection_dispatch (DBusConnection *connection)
}
else
{
+ if (connection->exit_on_disconnect &&
+ dbus_message_is_signal (message,
+ DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
+ "Disconnected"))
+ {
+ _dbus_verbose ("Exiting on Disconnected signal\n");
+ CONNECTION_UNLOCK (connection);
+ _dbus_exit (1);
+ _dbus_assert_not_reached ("Call to exit() returned");
+ }
+
_dbus_list_free_link (message_link);
dbus_message_unref (message); /* don't want the message to count in max message limits
* in computing dispatch status below