From fd18e1f4bf40481570ec20f1261b111d15f6c923 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 8 Apr 2010 00:52:50 +0200 Subject: dbus: fix dbus event loop hookup --- dbus.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/dbus.c b/dbus.c index 546a7c59eb..ab32b9f81f 100644 --- a/dbus.c +++ b/dbus.c @@ -363,17 +363,19 @@ static DBusHandlerResult system_bus_message_filter(DBusConnection *connection, unsigned bus_dispatch(Manager *m) { assert(m); - if (m->request_api_bus_dispatch) - if (dbus_connection_dispatch(m->api_bus) == DBUS_DISPATCH_COMPLETE) { + if (m->request_api_bus_dispatch) { + if (dbus_connection_dispatch(m->api_bus) == DBUS_DISPATCH_COMPLETE) m->request_api_bus_dispatch = false; - return 1; - } - if (m->request_system_bus_dispatch) - if (dbus_connection_dispatch(m->system_bus) == DBUS_DISPATCH_COMPLETE) { + return 1; + } + + if (m->request_system_bus_dispatch) { + if (dbus_connection_dispatch(m->system_bus) == DBUS_DISPATCH_COMPLETE) m->request_system_bus_dispatch = false; - return 1; - } + + return 1; + } return 0; } @@ -471,6 +473,7 @@ static int bus_setup_loop(Manager *m, DBusConnection *bus) { assert(bus); dbus_connection_set_exit_on_disconnect(bus, FALSE); + if (!dbus_connection_set_watch_functions(bus, bus_add_watch, bus_remove_watch, bus_toggle_watch, m, NULL) || !dbus_connection_set_timeout_functions(bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL)) return -ENOMEM; @@ -499,12 +502,13 @@ int bus_init_system(Manager *m) { return 0; } + dbus_connection_set_dispatch_status_function(m->system_bus, system_bus_dispatch_status, m, NULL); + m->request_system_bus_dispatch = true; + if ((r = bus_setup_loop(m, m->system_bus)) < 0) { bus_done_system(m); return r; } - - dbus_connection_set_dispatch_status_function(m->system_bus, system_bus_dispatch_status, m, NULL); } if (!dbus_connection_add_filter(m->system_bus, system_bus_message_filter, m, NULL)) { @@ -530,8 +534,6 @@ int bus_init_system(Manager *m) { strnull(dbus_bus_get_unique_name(m->system_bus))); dbus_free(id); - m->request_system_bus_dispatch = true; - return 0; } @@ -556,12 +558,13 @@ int bus_init_api(Manager *m) { return 0; } + dbus_connection_set_dispatch_status_function(m->api_bus, api_bus_dispatch_status, m, NULL); + m->request_api_bus_dispatch = true; + if ((r = bus_setup_loop(m, m->api_bus)) < 0) { bus_done_api(m); return r; } - - dbus_connection_set_dispatch_status_function(m->api_bus, api_bus_dispatch_status, m, NULL); } if (!dbus_connection_register_object_path(m->api_bus, "/org/freedesktop/systemd1", &bus_manager_vtable, m) || @@ -600,8 +603,6 @@ int bus_init_api(Manager *m) { if (!(m->subscribed = set_new(string_hash_func, string_compare_func))) return -ENOMEM; - m->request_api_bus_dispatch = true; - return 0; } -- cgit v1.2.3-54-g00ecf