← Back to team overview

ubuntu-multiseat team mailing list archive

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

 

Laércio de Sousa has proposed merging lp:~ubuntu-multiseat/lightdm/simple-globbing-in-seat-config-section into lp:lightdm.

Requested reviews:
  Robert Ancell (robert-ancell)
Related bugs:
  Bug #1364911 in Light Display Manager: "Support globbing in seat config sections"
  https://bugs.launchpad.net/lightdm/+bug/1364911

For more details, see:
https://code.launchpad.net/~ubuntu-multiseat/lightdm/simple-globbing-in-seat-config-section/+merge/233220

[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.
-- 
https://code.launchpad.net/~ubuntu-multiseat/lightdm/simple-globbing-in-seat-config-section/+merge/233220
Your team Ubuntu Multiseat is subscribed to branch lp:~ubuntu-multiseat/lightdm/simple-globbing-in-seat-config-section.
=== modified file 'src/lightdm.c'
--- src/lightdm.c	2014-09-03 05:21:46 +0000
+++ src/lightdm.c	2014-09-03 14:01:08 +0000
@@ -145,32 +145,53 @@
     g_free (path);
 }
 
+static GList*
+get_config_sections (const gchar *seat_name)
+{
+    gchar **groups, **i;
+    GList *config_sections = NULL;
+
+    config_sections = g_list_append (config_sections, g_strdup ("SeatDefaults"));
+
+    if (!seat_name)
+        return config_sections;
+
+    groups = config_get_groups (config_get_instance ());
+    for (i = groups; *i; i++)
+    {
+        if (g_str_has_prefix (*i, "Seat:"))
+        {
+            const gchar *seat_name_glob = *i + strlen ("Seat:");
+            if (g_pattern_match_simple (seat_name_glob, seat_name))
+                config_sections = g_list_append (config_sections, g_strdup (*i));
+        }
+    }
+    g_strfreev (groups);
+
+    return config_sections;
+}
+
 static void
-set_seat_properties (Seat *seat, const gchar *config_section)
+set_seat_properties (Seat *seat, const gchar *seat_name)
 {
+    GList *sections, *link;
     gchar **keys;
     gint i;
 
-    keys = config_get_keys (config_get_instance (), "SeatDefaults");
-    for (i = 0; keys && keys[i]; i++)
-    {
-        gchar *value = config_get_string (config_get_instance (), "SeatDefaults", keys[i]);
-        seat_set_property (seat, keys[i], value);
-        g_free (value);
-    }
-    g_strfreev (keys);
-
-    if (config_section)
-    {
-        keys = config_get_keys (config_get_instance (), config_section);
+    sections = get_config_sections (seat_name);
+    for (link = sections; link; link = link->next)
+    {
+        const gchar *section = link->data;
+        keys = config_get_keys (config_get_instance (), section);
         for (i = 0; keys && keys[i]; i++)
         {
-            gchar *value = config_get_string (config_get_instance (), config_section, keys[i]);
+            gchar *value = config_get_string (config_get_instance (), section, keys[i]);
             seat_set_property (seat, keys[i], value);
             g_free (value);
         }
         g_strfreev (keys);
     }
+    g_list_free_full (sections, g_free);
 }
 
 static void
@@ -221,11 +242,7 @@
 
     if (next_seat)
     {
-        gchar *config_section;
-
-        config_section = g_strdup_printf ("Seat:%s", seat_get_name (seat));
-        set_seat_properties (next_seat, config_section);
-        g_free (config_section);
+        set_seat_properties (next_seat, seat_get_name (seat));
 
         // We set this manually on default seat.  Let's port it over if needed.
         if (seat_get_boolean_property (seat, "exit-on-failure"))
@@ -938,42 +955,32 @@
 add_login1_seat (Login1Seat *login1_seat)
 {
     const gchar *seat_name = login1_seat_get_id (login1_seat);
-    gchar **groups, **i;
-    gchar *config_section = NULL;
     gchar **types = NULL, **type;
+    GList *config_sections = NULL, *link;
     Seat *seat = NULL;
     gboolean is_seat0, started = FALSE;
 
     g_debug ("New seat added from logind: %s", seat_name);
     is_seat0 = strcmp (seat_name, "seat0") == 0;
 
-    groups = config_get_groups (config_get_instance ());
-    for (i = groups; !config_section && *i; i++)
-    {
-        if (g_str_has_prefix (*i, "Seat:") &&
-            g_str_has_suffix (*i, seat_name))
-        {
-            config_section = g_strdup (*i);
-            break;
-        }
-    }
-    g_strfreev (groups);
-
-    if (config_section)
-    {
+    config_sections = get_config_sections (seat_name);
+    for (link = g_list_last (config_sections); link; link = link->next)
+    {
+        gchar *config_section = link->data;
         g_debug ("Loading properties from config section %s", config_section);
         types = config_get_string_list (config_get_instance (), config_section, "type");
+        if (types)
+            break;
     }
+    g_list_free_full (config_sections, g_free);
 
-    if (!types)
-        types = config_get_string_list (config_get_instance (), "SeatDefaults", "type");
     for (type = types; !seat && type && *type; type++)
         seat = seat_new (*type, seat_name);
     g_strfreev (types);
 
     if (seat)
     {
-        set_seat_properties (seat, NULL);
+        set_seat_properties (seat, seat_name);
 
         if (!login1_seat_get_can_multi_session (login1_seat))
         {
@@ -981,9 +988,6 @@
             seat_set_property (seat, "allow-user-switching", "false");
         }
 
-        if (config_section)
-            set_seat_properties (seat, config_section);
-
         if (is_seat0)
             seat_set_property (seat, "exit-on-failure", "true");
     }
@@ -997,7 +1001,6 @@
             g_debug ("Failed to start seat: %s", seat_name);
     }
 
-    g_free (config_section);
     g_object_unref (seat);
   
     return started;

=== modified file 'src/unity-system-compositor.c'
--- src/unity-system-compositor.c	2014-05-28 15:38:19 +0000
+++ src/unity-system-compositor.c	2014-09-03 14:01:08 +0000
@@ -85,6 +85,8 @@
 unity_system_compositor_set_command (UnitySystemCompositor *compositor, const gchar *command)
 {
     g_return_if_fail (compositor != NULL);
+    g_return_if_fail (command != NULL);
+
     g_free (compositor->priv->command);
     compositor->priv->command = g_strdup (command);
 }


Follow ups