summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-07-27 18:16:15 +0200
committerLennart Poettering <lennart@poettering.net>2009-08-12 03:54:03 +0200
commit8535db29009c48a37fc2559ca0fcc5b366e1e122 (patch)
tree3b32b49ee638c7c62fed253471757f9bc906ca3d
parent17fe9ecafedffde111fd0ac95d5688bf5a330972 (diff)
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.
-rw-r--r--src/ck-manager.c29
-rw-r--r--src/ck-seat.c19
-rw-r--r--src/ck-seat.h2
3 files changed, 23 insertions, 27 deletions
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);
diff --git a/src/ck-seat.c b/src/ck-seat.c
index 8edaaeb..27ccf14 100644
--- a/src/ck-seat.c
+++ b/src/ck-seat.c
@@ -741,8 +741,8 @@ active_vt_changed (CkVtMonitor *vt_monitor,
update_active_vt (seat, num);
}
-static gboolean
-register_seat (CkSeat *seat)
+gboolean
+ck_seat_register (CkSeat *seat)
{
GError *error = NULL;
@@ -1023,19 +1023,12 @@ ck_seat_new (const char *sid,
CkSeatKind kind)
{
GObject *object;
- gboolean res;
object = g_object_new (CK_TYPE_SEAT,
"id", sid,
"kind", kind,
NULL);
- res = register_seat (CK_SEAT (object));
- if (! res) {
- g_object_unref (object);
- return NULL;
- }
-
return CK_SEAT (object);
}
@@ -1045,7 +1038,6 @@ ck_seat_new_with_devices (const char *sid,
GPtrArray *devices)
{
GObject *object;
- gboolean res;
int i;
object = g_object_new (CK_TYPE_SEAT,
@@ -1059,12 +1051,6 @@ ck_seat_new_with_devices (const char *sid,
}
}
- res = register_seat (CK_SEAT (object));
- if (! res) {
- g_object_unref (object);
- return NULL;
- }
-
return CK_SEAT (object);
}
@@ -1232,4 +1218,3 @@ ck_seat_dump (CkSeat *seat,
g_free (group_name);
}
-
diff --git a/src/ck-seat.h b/src/ck-seat.h
index efae465..47d10a7 100644
--- a/src/ck-seat.h
+++ b/src/ck-seat.h
@@ -91,6 +91,8 @@ CkSeat * ck_seat_new_with_devices (const char *sid,
CkSeatKind kind,
GPtrArray *devices);
+gboolean ck_seat_register (CkSeat *seat);
+
void ck_seat_dump (CkSeat *seat,
GKeyFile *key_file);