From 08aabc2bee64d26986a3e15c49d6522cbede62a0 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 11 Apr 2011 16:35:38 -0500 Subject: [PATCH] core: aggregate ConsoleKit sesson data (bgo #647454) Jan Schmidt noticed that things didn't work as expected with multiple sessions of the same user, since when inserting the new session the old one was forgotten. Thus bad things happened if you were local in the old session but not in the new one since only the new one would be considered. Instead, make the actual data stored the aggregate of all sessions for that user. --- src/nm-session-monitor.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/nm-session-monitor.c b/src/nm-session-monitor.c index 4877b7703..c701bdb3b 100644 --- a/src/nm-session-monitor.c +++ b/src/nm-session-monitor.c @@ -189,6 +189,19 @@ error: return NULL; } +static void +session_merge (Session *src, Session *dest) +{ + g_return_if_fail (src != NULL); + g_return_if_fail (dest != NULL); + + g_warn_if_fail (g_strcmp0 (src->user, dest->user) == 0); + g_warn_if_fail (src->uid == dest->uid); + + dest->local = (dest->local || src->local); + dest->active = (dest->active || src->active); +} + /********************************************************************/ static void @@ -237,14 +250,24 @@ reload_database (NMSessionMonitor *self, GError **error) } for (i = 0; i < len; i++) { + Session *found; + if (!g_str_has_prefix (groups[i], "Session ")) continue; s = session_new (self->database, groups[i], error); if (!s) goto error; - g_hash_table_insert (self->sessions_by_user, (gpointer) s->user, s); - g_hash_table_insert (self->sessions_by_uid, GUINT_TO_POINTER (s->uid), s); + + found = g_hash_table_lookup (self->sessions_by_user, (gpointer) s->user); + if (found) { + session_merge (s, found); + session_free (s); + } else { + /* Entirely new user */ + g_hash_table_insert (self->sessions_by_user, (gpointer) s->user, s); + g_hash_table_insert (self->sessions_by_uid, GUINT_TO_POINTER (s->uid), s); + } } g_strfreev (groups);