File gdm-remove-duplicate-sessions.patch of Package gdm
159
1
From beee85a6ee398f7f8d3ba09c148006c6d04c84c0 Mon Sep 17 00:00:00 2001
2
From: Iain Lane <iainl@gnome.org>
3
Date: Fri, 15 Mar 2019 17:51:45 +0000
4
Subject: [PATCH] libgdm: Remove duplicate sessions once, after all sessions
5
have been processed
6
MIME-Version: 1.0
7
Content-Type: text/plain; charset=UTF-8
8
Content-Transfer-Encoding: 8bit
9
10
We add sessions to a hash table keyed on the basename without extension,
11
and while we're adding them we de-duplicate based on the translated name
12
(the text that will be visible in the switcher).
13
14
This has a problem. In this situation:
15
16
```
17
laney@disco:~$ tree /usr/share/{wayland-,x}sessions/
18
/usr/share/wayland-sessions/
19
├── gnome.desktop
20
└── ubuntu-wayland.desktop
21
/usr/share/xsessions/
22
├── gnome.desktop -> gnome-xorg.desktop
23
├── gnome-xorg.desktop
24
└── ubuntu.desktop
25
```
26
27
We process the X sessions first, and then the Wayland sessions. The
28
deduplication might end up removing `xsessions/gnome-xorg` and leaving
29
`xsessions/gnome`. Then when we come to process the Wayland sessions, we
30
will clobber `xsessions/gnome` with `wayland-sessions/gnome`, as they
31
have the same ID.
32
33
When everything is working, it is actually *intentional* that
34
`xsessions/gnome` gets clobbered, so that you end up seeing "GNOME"
35
(wayland) and "GNOME on Xorg" in the switcher, and not (e.g.) "GNOME on
36
Xorg" twice, and you have the correct fallback behaviour in case you ever
37
enable/disable Wayland.
38
39
Instead of filtering while we add things, we can add all the sessions we
40
find (clobbering duplicate IDs as before), and then process the list
41
once at the end, removing sessions with duplicated visible names at that
42
point.
43
44
Closes: #473
45
---
46
libgdm/gdm-sessions.c | 47 ++++++++++++++++++++++++++++---------------
47
1 file changed, 31 insertions(+), 16 deletions(-)
48
49
From e2a1c7f63003a6a80e861f6dc0b6c060a6d7385c Mon Sep 17 00:00:00 2001
50
From: Iain Lane <iainl@gnome.org>
51
Date: Sat, 16 Mar 2019 11:40:46 +0000
52
Subject: [PATCH] libgdm: Always de-duplicate
53
54
I put this inside an `#ifdef ENABLE_WAYLAND_SUPPORT` before, which would
55
mean that it's not called if that's not defined.
56
---
57
libgdm/gdm-sessions.c | 2 +-
58
1 file changed, 1 insertion(+), 1 deletion(-)
59
60
diff --git a/libgdm/gdm-sessions.c b/libgdm/gdm-sessions.c
61
index 99bb68f..c1b6f24 100644
62
--- a/libgdm/gdm-sessions.c
63
+++ b/libgdm/gdm-sessions.c
64
65
return TRUE;
66
}
67
68
-static gboolean
69
-find_translated_name (gpointer key,
70
- gpointer value,
71
- gpointer user_data)
72
-{
73
- char *id = key;
74
- GdmSessionFile *session = value;
75
- char *translated_name = user_data;
76
- return g_strcmp0 (session->translated_name, translated_name) == 0;
77
-}
78
-
79
static void
80
load_session_file (const char *id,
81
const char *path)
82
83
GKeyFile *key_file;
84
GError *error;
85
gboolean res;
86
- GdmSessionFile *session, *psession;
87
+ GdmSessionFile *session;
88
89
key_file = g_key_file_new ();
90
91
92
session->translated_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Name", NULL, NULL);
93
session->translated_comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Comment", NULL, NULL);
94
95
- psession = g_hash_table_find (gdm_available_sessions_map, find_translated_name, session->translated_name);
96
-
97
- if(psession)
98
- g_hash_table_remove (gdm_available_sessions_map, psession->id);
99
-
100
g_hash_table_insert (gdm_available_sessions_map, g_strdup (id), session);
101
102
out:
103
g_key_file_free (key_file);
104
}
105
106
+static gboolean
107
+remove_duplicate_sessions (gpointer key,
108
+ gpointer value,
109
+ gpointer user_data)
110
+{
111
+ gboolean already_known;
112
+ const char *id;
113
+ GHashTable *names_seen_before;
114
+ GdmSessionFile *session;
115
+
116
+ id = (const char *) key;
117
+ names_seen_before = (GHashTable *) user_data;
118
+ session = (GdmSessionFile *) value;
119
+ already_known = !g_hash_table_add (names_seen_before, session->translated_name);
120
+
121
+ if (already_known)
122
+ g_debug ("GdmSession: Removing %s (%s) as we already have a session by this name",
123
+ session->id,
124
+ session->path);
125
+
126
+ return already_known;
127
+}
128
+
129
static void
130
collect_sessions_from_directory (const char *dirname)
131
{
132
133
static void
134
collect_sessions (void)
135
{
136
+ g_autoptr(GHashTable) names_seen_before = NULL;
137
int i;
138
const char *xorg_search_dirs[] = {
139
"/etc/X11/sessions/",
140
141
NULL
142
};
143
144
+ names_seen_before = g_hash_table_new (g_str_hash, g_str_equal);
145
+
146
#ifdef ENABLE_WAYLAND_SUPPORT
147
const char *wayland_search_dirs[] = {
148
DATADIR "/wayland-sessions/",
149
150
collect_sessions_from_directory (wayland_search_dirs [i]);
151
}
152
#endif
153
+ g_hash_table_foreach_remove (gdm_available_sessions_map,
154
+ remove_duplicate_sessions,
155
+ names_seen_before);
156
}
157
158
/**
159