From 8535db29009c48a37fc2559ca0fcc5b366e1e122 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 27 Jul 2009 18:16:15 +0200 Subject: database: write the console database to disk before signalling via dbus We simply change the order how the signal handlers for D-Bus and the database dumping are registered. According to the gobject docs it is guaranteed that the signal handlers are run in the same order as they are registered, so this should be safe and have the desired effect. --- src/ck-manager.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/ck-manager.c') diff --git a/src/ck-manager.c b/src/ck-manager.c index d5d2c65..440163b 100644 --- a/src/ck-manager.c +++ b/src/ck-manager.c @@ -1304,13 +1304,21 @@ add_new_seat (CkManager *manager, sid = generate_seat_id (manager); seat = ck_seat_new (sid, kind); - if (seat == NULL) { - /* returns null if connection to bus fails */ - g_free (sid); - goto out; - } + + /* First we connect our own signals to the seat, followed by + * the D-Bus signal hookup to make sure we can first dump the + * database and only then send out the D-Bus signals for + * it. GObject guarantees us that the signal handlers are + * called in the same order as they are registered. */ connect_seat_signals (manager, seat); + if (!ck_seat_register (seat)) { + /* returns false if connection to bus fails */ + disconnect_seat_signals (manager, seat); + g_object_unref (seat); + g_free (sid); + return NULL; + } g_hash_table_insert (manager->priv->seats, sid, seat); @@ -1322,7 +1330,6 @@ add_new_seat (CkManager *manager, log_seat_added_event (manager, seat); - out: return seat; } @@ -2407,14 +2414,16 @@ add_seat_for_file (CkManager *manager, sid = generate_seat_id (manager); seat = ck_seat_new_from_file (sid, filename); - if (seat == NULL) { - /* returns null if connection to bus fails */ + + connect_seat_signals (manager, seat); + if (!ck_seat_register (seat)) { + /* returns false if connection to bus fails */ + disconnect_seat_signals (manager, seat); + g_object_unref (seat); g_free (sid); return; } - connect_seat_signals (manager, seat); - g_hash_table_insert (manager->priv->seats, sid, seat); g_debug ("Added seat: %s", sid); -- cgit