summaryrefslogtreecommitdiff
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
parenta683a80c409cc4f2e57ba6a3e60d52f91b8657d0 (diff)
downloaddbus-25cb861980003f81eade8707bfa1a61c9ece1779.tar.gz
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
-rw-r--r--ChangeLog10
-rw-r--r--dbus/dbus-bus.c6
-rw-r--r--dbus/dbus-connection.c38
-rw-r--r--dbus/dbus-connection.h4
4 files changed, 57 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 68dfde4d..1431a96c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
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
+
+2003-09-21 Havoc Pennington <hp@pobox.com>
+
Get matching rules mostly working in the bus; only actually
parsing the rule text remains. However, the client side of
"signal connections" hasn't been started, this patch is only the
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;