Merge lp:~ubuntu-multiseat/lightdm/simple-globbing-in-seat-config-section into lp:lightdm

Proposed by Laércio de Sousa
Status: Merged
Merged at revision: 2076
Proposed branch: lp:~ubuntu-multiseat/lightdm/simple-globbing-in-seat-config-section
Merge into: lp:lightdm
Diff against target: 306 lines (+158/-44)
5 files modified
src/lightdm.c (+47/-44)
src/unity-system-compositor.c (+2/-0)
tests/Makefile.am (+2/-0)
tests/scripts/multi-seat-globbing-config-sections.conf (+105/-0)
tests/test-multi-seat-globbing-config-sections (+2/-0)
To merge this branch: bzr merge lp:~ubuntu-multiseat/lightdm/simple-globbing-in-seat-config-section
Reviewer Review Type Date Requested Status
Robert Ancell Approve
Review via email: mp+233220@code.launchpad.net

This proposal supersedes a proposal from 2014-08-27.

Description of the change

[UPDATE] Resubmitting this merge proposal after Robert Ancell's updates

Add support for simple globbing in seat config sections.

Example: if a config section [Seat:seatFoo*] is available in lightdm.conf, it will match any seat name starting with "seatFoo", like "seatFooBar", "seatFooBaz", etc.

In particular, [Seat:seat*] will match any seat added from logind (including seat0), and [Seat:*] will match any seat (including those eventually added from other mechanisms than logind), just as [SeatDefaults] currently does.

To post a comment you must log in.
Revision history for this message
Laércio de Sousa (lbssousa) wrote : Posted in a previous version of this proposal

[NEW ISSUE] New function get_config_section() should return a list of all available globbing config sections that match a given seat name (including the exact match), not only the first occurrence.

Revision history for this message
Robert Ancell (robert-ancell) wrote : Posted in a previous version of this proposal

Yes, you could match against n-sections. Also, you should use the GLib pattern matcher [1]

[1] https://developer.gnome.org/glib/stable/glib-Glob-style-pattern-matching.html

review: Needs Fixing
Revision history for this message
Robert Ancell (robert-ancell) wrote : Posted in a previous version of this proposal

Will also need a regression test to confirm this matching works

Revision history for this message
Laércio de Sousa (lbssousa) wrote : Posted in a previous version of this proposal

> Yes, you could match against n-sections. Also, you should use the GLib pattern
> matcher [1]
>
> [1] https://developer.gnome.org/glib/stable/glib-Glob-style-pattern-
> matching.html

Done.

Revision history for this message
Laércio de Sousa (lbssousa) wrote : Posted in a previous version of this proposal

> Will also need a regression test to confirm this matching works

I've written a regression test that starts 3 seats and enables autologin as guest with different timeouts for the non-seat0 ones. My local "make check" returns FAIL to this test, but I could not see any relevant error message in test log.

Could you review it, please?

Revision history for this message
Laércio de Sousa (lbssousa) wrote : Posted in a previous version of this proposal

[NEW IDEA] Support wildcard %s when setting seat property values, which will be replaced with corresponding seat name.

Revision history for this message
Laércio de Sousa (lbssousa) wrote : Posted in a previous version of this proposal

Example:

[Seat:seat-*]
xserver-command=X -config xorg.conf.%s

Revision history for this message
Robert Ancell (robert-ancell) wrote : Posted in a previous version of this proposal

There were some typos in the script but the main reason was the seat IDs (e.g. "seat-AAA-Foo") were being converted into invalid D-Bus address names (e.g. "/org/freedesktop/login1/seat/seat-AAA-Foo" - "_" is not allowed in D-Bus addresses). So there was a bug in my mock login1 code in tests/src/test-runner.c

I fixed that up and simplified the test.

Thanks!

Revision history for this message
Robert Ancell (robert-ancell) wrote : Posted in a previous version of this proposal

The wildcard idea sounds good, things to think about:
- Does the wildcard work in all config values or just command?
- Could this wildcard be a valid value in other cases and will those values now have to be escaped (potentially breaking existing config)? For this reason, we should use a bigger token, e.g. "%(seat-name)" which is both more self-explanatory and less likely to collide with something else.
- What are the escape rules if you need a literal "%s"?
- Are there other values we should give?

As always, please open a new MP and/or bug for this feature.

2047. By Laércio de Sousa

Reintroduce test after merge with trunk.

2048. By Laércio de Sousa

Remove dashes from logind seat IDs in test script

2049. By Laércio de Sousa

Fix iteration pointer when iterating backwards on GList object

2050. By Laércio de Sousa

Move debug message from add_login1_seat() to set_seat_properties() body.

2051. By Laércio de Sousa

Merge with trunk

2052. By Laércio de Sousa

Remove duplicated line after merging with trunk

Revision history for this message
Laércio de Sousa (lbssousa) wrote :

Just updated this branch after 1.11.9 release. Some conflicts resolved.

Revision history for this message
Robert Ancell (robert-ancell) wrote :

This is going to be too late for the 1.12 release, we will land it into 1.14.

Revision history for this message
Robert Ancell (robert-ancell) wrote :

Seems to be working now, thanks Laércio!

Revision history for this message
Robert Ancell (robert-ancell) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lightdm.c'
2--- src/lightdm.c 2014-09-10 03:33:25 +0000
3+++ src/lightdm.c 2014-09-10 13:35:17 +0000
4@@ -147,32 +147,54 @@
5 g_free (path);
6 }
7
8+static GList*
9+get_config_sections (const gchar *seat_name)
10+{
11+ gchar **groups, **i;
12+ GList *config_sections = NULL;
13+
14+ config_sections = g_list_append (config_sections, g_strdup ("SeatDefaults"));
15+
16+ if (!seat_name)
17+ return config_sections;
18+
19+ groups = config_get_groups (config_get_instance ());
20+ for (i = groups; *i; i++)
21+ {
22+ if (g_str_has_prefix (*i, "Seat:"))
23+ {
24+ const gchar *seat_name_glob = *i + strlen ("Seat:");
25+ if (g_pattern_match_simple (seat_name_glob, seat_name))
26+ config_sections = g_list_append (config_sections, g_strdup (*i));
27+ }
28+ }
29+ g_strfreev (groups);
30+
31+ return config_sections;
32+}
33+
34 static void
35-set_seat_properties (Seat *seat, const gchar *config_section)
36+set_seat_properties (Seat *seat, const gchar *seat_name)
37 {
38+ GList *sections, *link;
39 gchar **keys;
40 gint i;
41
42- keys = config_get_keys (config_get_instance (), "SeatDefaults");
43- for (i = 0; keys && keys[i]; i++)
44- {
45- gchar *value = config_get_string (config_get_instance (), "SeatDefaults", keys[i]);
46- seat_set_property (seat, keys[i], value);
47- g_free (value);
48- }
49- g_strfreev (keys);
50-
51- if (config_section)
52- {
53- keys = config_get_keys (config_get_instance (), config_section);
54+ sections = get_config_sections (seat_name);
55+ for (link = sections; link; link = link->next)
56+ {
57+ const gchar *section = link->data;
58+ g_debug ("Loading properties from config section %s", section);
59+ keys = config_get_keys (config_get_instance (), section);
60 for (i = 0; keys && keys[i]; i++)
61 {
62- gchar *value = config_get_string (config_get_instance (), config_section, keys[i]);
63+ gchar *value = config_get_string (config_get_instance (), section, keys[i]);
64 seat_set_property (seat, keys[i], value);
65 g_free (value);
66 }
67 g_strfreev (keys);
68 }
69+ g_list_free_full (sections, g_free);
70 }
71
72 static void
73@@ -223,11 +245,7 @@
74
75 if (next_seat)
76 {
77- gchar *config_section;
78-
79- config_section = g_strdup_printf ("Seat:%s", seat_get_name (seat));
80- set_seat_properties (next_seat, config_section);
81- g_free (config_section);
82+ set_seat_properties (next_seat, seat_get_name (seat));
83
84 // We set this manually on default seat. Let's port it over if needed.
85 if (seat_get_boolean_property (seat, "exit-on-failure"))
86@@ -940,42 +958,31 @@
87 add_login1_seat (Login1Seat *login1_seat)
88 {
89 const gchar *seat_name = login1_seat_get_id (login1_seat);
90- gchar **groups, **i;
91- gchar *config_section = NULL;
92 gchar **types = NULL, **type;
93+ GList *config_sections = NULL, *link;
94 Seat *seat = NULL;
95 gboolean is_seat0, started = FALSE;
96
97 g_debug ("New seat added from logind: %s", seat_name);
98 is_seat0 = strcmp (seat_name, "seat0") == 0;
99
100- groups = config_get_groups (config_get_instance ());
101- for (i = groups; !config_section && *i; i++)
102+ config_sections = get_config_sections (seat_name);
103+ for (link = g_list_last (config_sections); link; link = link->prev)
104 {
105- if (g_str_has_prefix (*i, "Seat:") &&
106- g_str_has_suffix (*i, seat_name))
107- {
108- config_section = g_strdup (*i);
109+ gchar *config_section = link->data;
110+ types = config_get_string_list (config_get_instance (), config_section, "type");
111+ if (types)
112 break;
113- }
114- }
115- g_strfreev (groups);
116-
117- if (config_section)
118- {
119- g_debug ("Loading properties from config section %s", config_section);
120- types = config_get_string_list (config_get_instance (), config_section, "type");
121- }
122-
123- if (!types)
124- types = config_get_string_list (config_get_instance (), "SeatDefaults", "type");
125+ }
126+ g_list_free_full (config_sections, g_free);
127+
128 for (type = types; !seat && type && *type; type++)
129 seat = seat_new (*type, seat_name);
130 g_strfreev (types);
131
132 if (seat)
133 {
134- set_seat_properties (seat, NULL);
135+ set_seat_properties (seat, seat_name);
136
137 if (!login1_seat_get_can_multi_session (login1_seat))
138 {
139@@ -983,9 +990,6 @@
140 seat_set_property (seat, "allow-user-switching", "false");
141 }
142
143- if (config_section)
144- set_seat_properties (seat, config_section);
145-
146 if (is_seat0)
147 seat_set_property (seat, "exit-on-failure", "true");
148 }
149@@ -999,7 +1003,6 @@
150 g_debug ("Failed to start seat: %s", seat_name);
151 }
152
153- g_free (config_section);
154 g_object_unref (seat);
155
156 return started;
157
158=== modified file 'src/unity-system-compositor.c'
159--- src/unity-system-compositor.c 2014-09-05 02:18:15 +0000
160+++ src/unity-system-compositor.c 2014-09-10 13:35:17 +0000
161@@ -85,6 +85,8 @@
162 unity_system_compositor_set_command (UnitySystemCompositor *compositor, const gchar *command)
163 {
164 g_return_if_fail (compositor != NULL);
165+ g_return_if_fail (command != NULL);
166+
167 g_free (compositor->priv->command);
168 compositor->priv->command = g_strdup (command);
169 }
170
171=== modified file 'tests/Makefile.am'
172--- tests/Makefile.am 2014-09-10 03:33:25 +0000
173+++ tests/Makefile.am 2014-09-10 13:35:17 +0000
174@@ -187,6 +187,7 @@
175 test-multi-seat-non-graphical-disabled \
176 test-multi-seat-change-graphical \
177 test-multi-seat-change-graphical-disabled \
178+ test-multi-seat-globbing-config-sections \
179 test-mir-autologin \
180 test-mir-greeter \
181 test-mir-session \
182@@ -456,6 +457,7 @@
183 scripts/multi-seat-non-graphical-disabled.conf \
184 scripts/multi-seat-seat0-non-graphical.conf \
185 scripts/multi-seat-seat0-non-graphical-disabled.conf \
186+ scripts/multi-seat-globbing-config-sections.conf \
187 scripts/no-accounts-service.conf \
188 scripts/no-config.conf \
189 scripts/no-console-kit.conf \
190
191=== added file 'tests/scripts/multi-seat-globbing-config-sections.conf'
192--- tests/scripts/multi-seat-globbing-config-sections.conf 1970-01-01 00:00:00 +0000
193+++ tests/scripts/multi-seat-globbing-config-sections.conf 2014-09-10 13:35:17 +0000
194@@ -0,0 +1,105 @@
195+#
196+# Check can set globbing config sections matching different seats
197+#
198+
199+[Seat:*]
200+autologin-user=have-password1
201+user-session=default
202+
203+[Seat:seat*Foo]
204+autologin-user-timeout=99
205+
206+[Seat:seatAAAFoo]
207+autologin-user=have-password2
208+
209+[Seat:seatBBB*]
210+autologin-user=have-password3
211+
212+#?*START-DAEMON
213+#?RUNNER DAEMON-START
214+
215+# seat0 starts
216+#?XSERVER-0 START VT=7 SEAT=seat0
217+#?*XSERVER-0 INDICATE-READY
218+#?XSERVER-0 INDICATE-READY
219+#?XSERVER-0 ACCEPT-CONNECT
220+
221+# Session starts for configured user
222+#?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_GREETER_DATA_DIR=.*/have-password1 XDG_SESSION_TYPE=x11 XDG_SESSION_DESKTOP=default USER=have-password1
223+#?LOGIN1 ACTIVATE-SESSION SESSION=c0
224+#?XSERVER-0 ACCEPT-CONNECT
225+#?SESSION-X-0 CONNECT-XSERVER
226+
227+# Add seatAAAFoo
228+#?*ADD-SEAT ID=seatAAAFoo
229+
230+# seatAAAFoo starts
231+#?XSERVER-1 START SEAT=seatAAAFoo SHAREVTS=TRUE
232+#?*XSERVER-1 INDICATE-READY
233+#?XSERVER-1 INDICATE-READY
234+#?XSERVER-1 ACCEPT-CONNECT
235+
236+# Greeter starts
237+#?GREETER-X-1 START XDG_SEAT=seatAAAFoo XDG_SESSION_CLASS=greeter
238+#?LOGIN1 ACTIVATE-SESSION SESSION=c1
239+#?XSERVER-1 ACCEPT-CONNECT
240+#?GREETER-X-1 CONNECT-XSERVER
241+#?GREETER-X-1 CONNECT-TO-DAEMON
242+#?GREETER-X-1 CONNECTED-TO-DAEMON
243+
244+# Greeter is requested to timeout
245+#?GREETER-X-1 AUTOLOGIN-USER USERNAME=have-password2 TIMEOUT=99
246+
247+# Trigger autologin
248+#?*GREETER-X-1 AUTHENTICATE-AUTOLOGIN
249+#?GREETER-X-1 AUTHENTICATION-COMPLETE USERNAME=have-password2 AUTHENTICATED=TRUE
250+#?*GREETER-X-1 START-SESSION
251+#?GREETER-X-1 TERMINATE SIGNAL=15
252+
253+# Session starts for configured user
254+#?SESSION-X-1 START XDG_SEAT=seatAAAFoo XDG_GREETER_DATA_DIR=.*/have-password2 XDG_SESSION_TYPE=x11 XDG_SESSION_DESKTOP=default USER=have-password2
255+#?LOGIN1 ACTIVATE-SESSION SESSION=c2
256+#?XSERVER-1 ACCEPT-CONNECT
257+#?SESSION-X-1 CONNECT-XSERVER
258+
259+# Add seatBBBFoo
260+#?*ADD-SEAT ID=seatBBBFoo
261+
262+# seatBBBFoo starts
263+#?XSERVER-2 START SEAT=seatBBBFoo SHAREVTS=TRUE
264+#?*XSERVER-2 INDICATE-READY
265+#?XSERVER-2 INDICATE-READY
266+#?XSERVER-2 ACCEPT-CONNECT
267+
268+# Greeter starts
269+#?GREETER-X-2 START XDG_SEAT=seatBBBFoo XDG_SESSION_CLASS=greeter
270+#?LOGIN1 ACTIVATE-SESSION SESSION=c3
271+#?XSERVER-2 ACCEPT-CONNECT
272+#?GREETER-X-2 CONNECT-XSERVER
273+#?GREETER-X-2 CONNECT-TO-DAEMON
274+#?GREETER-X-2 CONNECTED-TO-DAEMON
275+
276+# Greeter is requested to timeout
277+#?GREETER-X-2 AUTOLOGIN-USER USERNAME=have-password3 TIMEOUT=99
278+
279+# Trigger autologin
280+#?*GREETER-X-2 AUTHENTICATE-AUTOLOGIN
281+#?GREETER-X-2 AUTHENTICATION-COMPLETE USERNAME=have-password3 AUTHENTICATED=TRUE
282+#?*GREETER-X-2 START-SESSION
283+#?GREETER-X-2 TERMINATE SIGNAL=15
284+
285+# Session starts for configured user
286+#?SESSION-X-2 START XDG_SEAT=seatBBBFoo XDG_GREETER_DATA_DIR=.*/have-password3 XDG_SESSION_TYPE=x11 XDG_SESSION_DESKTOP=default USER=have-password3
287+#?LOGIN1 ACTIVATE-SESSION SESSION=c4
288+#?XSERVER-2 ACCEPT-CONNECT
289+#?SESSION-X-2 CONNECT-XSERVER
290+
291+# Cleanup
292+#?*STOP-DAEMON
293+#?XSERVER-0 TERMINATE SIGNAL=15
294+#?SESSION-X-0 TERMINATE SIGNAL=15
295+#?XSERVER-1 TERMINATE SIGNAL=15
296+#?SESSION-X-1 TERMINATE SIGNAL=15
297+#?XSERVER-2 TERMINATE SIGNAL=15
298+#?SESSION-X-2 TERMINATE SIGNAL=15
299+#?RUNNER DAEMON-EXIT STATUS=0
300
301=== added file 'tests/test-multi-seat-globbing-config-sections'
302--- tests/test-multi-seat-globbing-config-sections 1970-01-01 00:00:00 +0000
303+++ tests/test-multi-seat-globbing-config-sections 2014-09-10 13:35:17 +0000
304@@ -0,0 +1,2 @@
305+#!/bin/sh
306+./src/dbus-env ./src/test-runner multi-seat-globbing-config-sections test-gobject-greeter

Subscribers

People subscribed via source and target branches