diff options
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-bus.c | 6 | ||||
-rw-r--r-- | dbus/dbus-connection.c | 38 | ||||
-rw-r--r-- | dbus/dbus-connection.h | 4 |
3 files changed, 47 insertions, 1 deletions
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c index a38b4a26..6d7cb82c 100644 --- a/dbus/dbus-bus.c +++ b/dbus/dbus-bus.c @@ -338,6 +338,12 @@ dbus_bus_get (DBusBusType type, _DBUS_UNLOCK (bus); return NULL; } + + /* By default we're bound to the lifecycle of + * the message bus. + */ + dbus_connection_set_exit_on_disconnect (connection, + TRUE); if (!dbus_bus_register (connection, error)) { 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 diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h index a4212c74..aa92b30a 100644 --- a/dbus/dbus-connection.h +++ b/dbus/dbus-connection.h @@ -100,6 +100,8 @@ void dbus_connection_unref (DBusConnection void dbus_connection_disconnect (DBusConnection *connection); dbus_bool_t dbus_connection_get_is_connected (DBusConnection *connection); dbus_bool_t dbus_connection_get_is_authenticated (DBusConnection *connection); +void dbus_connection_set_exit_on_disconnect (DBusConnection *connection, + dbus_bool_t exit_on_disconnect); void dbus_connection_flush (DBusConnection *connection); DBusMessage* dbus_connection_borrow_message (DBusConnection *connection); void dbus_connection_return_message (DBusConnection *connection, @@ -241,7 +243,7 @@ void dbus_connection_unregister_object_path (DBusConnection const char **path); dbus_bool_t dbus_connection_list_registered (DBusConnection *connection, - const char **parent_path, + const char **parent_path, char ***child_entries); DBUS_END_DECLS; |