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.
This commit is contained in:
@@ -189,6 +189,19 @@ error:
|
|||||||
return NULL;
|
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
|
static void
|
||||||
@@ -237,14 +250,24 @@ reload_database (NMSessionMonitor *self, GError **error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
|
Session *found;
|
||||||
|
|
||||||
if (!g_str_has_prefix (groups[i], "Session "))
|
if (!g_str_has_prefix (groups[i], "Session "))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
s = session_new (self->database, groups[i], error);
|
s = session_new (self->database, groups[i], error);
|
||||||
if (!s)
|
if (!s)
|
||||||
goto error;
|
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);
|
g_strfreev (groups);
|
||||||
|
Reference in New Issue
Block a user