]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Match seat configuration using globbing
authorRobert Ancell <robert.ancell@canonical.com>
Thu, 2 Oct 2014 06:51:36 +0000 (19:51 +1300)
committerRobert Ancell <robert.ancell@canonical.com>
Thu, 2 Oct 2014 06:51:36 +0000 (19:51 +1300)
1  2 
src/lightdm.c
src/unity-system-compositor.c
tests/Makefile.am

diff --combined src/lightdm.c
index f48af8bb5c02a1420949ae7a4c1e134c38ea46be,2a9bcf9a953e8fdb2787091d0dce0841fe2d1510..712d3bae1ea60a453263b2ae15e290199cb4f8d5
@@@ -147,32 -147,54 +147,54 @@@ log_init (void
      g_free (path);
  }
  
- static void
set_seat_properties (Seat *seat, const gchar *config_section)
+ static GList*
get_config_sections (const gchar *seat_name)
  {
-     gchar **keys;
-     gint i;
+     gchar **groups, **i;
+     GList *config_sections = NULL;
  
-     keys = config_get_keys (config_get_instance (), "SeatDefaults");
-     for (i = 0; keys && keys[i]; i++)
+     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++)
      {
-         gchar *value = config_get_string (config_get_instance (), "SeatDefaults", keys[i]);
-         seat_set_property (seat, keys[i], value);
-         g_free (value);
+         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 (keys);
+     g_strfreev (groups);
+     return config_sections;
+ }
  
-     if (config_section)
+ static void
+ set_seat_properties (Seat *seat, const gchar *seat_name)
+ {
+     GList *sections, *link;
+     gchar **keys;
+     gint i;
+     sections = get_config_sections (seat_name);
+     for (link = sections; link; link = link->next)
      {
-         keys = config_get_keys (config_get_instance (), config_section);
+         const gchar *section = link->data;
+         g_debug ("Loading properties from config section %s", section);
+         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
@@@ -223,11 -245,7 +245,7 @@@ display_manager_seat_removed_cb (Displa
  
      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"))
@@@ -569,7 -587,7 +587,7 @@@ emit_object_value_changed (GDBusConnect
                                          g_variant_new ("(sa{sv}as)", interface_name, &builder, NULL),
                                          &error))
          g_warning ("Failed to emit PropertiesChanged signal: %s", error->message);
 -    g_clear_error (&error); 
 +    g_clear_error (&error);
  }
  
  static void
@@@ -585,7 -603,7 +603,7 @@@ emit_object_signal (GDBusConnection *bu
                                          g_variant_new ("(o)", object_path),
                                          &error))
          g_warning ("Failed to emit %s signal on %s: %s", signal_name, path, error->message);
 -    g_clear_error (&error); 
 +    g_clear_error (&error);
  }
  
  static void
@@@ -940,42 -958,31 +958,31 @@@ static gboolea
  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->prev)
      {
-         g_debug ("Loading properties from config section %s", config_section);
+         gchar *config_section = link->data;
          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))
          {
              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");
      }
              g_debug ("Failed to start seat: %s", seat_name);
      }
  
-     g_free (config_section);
      g_object_unref (seat);
 -  
 +
      return started;
  }
  
index 405025570ee4cd4e70b64508194e3346fb906606,fd55f8e46350f2f3ea6cdf456c0bedb8cec21c39..b7970939925fac02cdec289e4c6d35277bf6be91
@@@ -1,7 -1,7 +1,7 @@@
  /*
   * Copyright (C) 2013 Canonical Ltd.
   * Author: Robert Ancell <robert.ancell@canonical.com>
 - * 
 + *
   * This program is free software: you can redistribute it and/or modify it under
   * the terms of the GNU General Public License as published by the Free Software
   * Foundation, either version 3 of the License, or (at your option) any later
@@@ -85,6 -85,8 +85,8 @@@ voi
  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);
  }
@@@ -238,7 -240,7 +240,7 @@@ read_cb (GIOChannel *source, GIOConditi
      gsize n_to_read = 0;
      guint16 id, payload_length;
      /*guint8 *payload;*/
 -  
 +
      if (condition == G_IO_HUP)
      {
          l_debug (compositor, "Compositor closed communication channel");
@@@ -459,7 -461,7 +461,7 @@@ unity_system_compositor_start (DisplayS
  
      return TRUE;
  }
 - 
 +
  static void
  unity_system_compositor_stop (DisplayServer *server)
  {
@@@ -481,7 -483,7 +483,7 @@@ unity_system_compositor_finalize (GObje
  {
      UnitySystemCompositor *self;
  
 -    self = UNITY_SYSTEM_COMPOSITOR (object);  
 +    self = UNITY_SYSTEM_COMPOSITOR (object);
  
      if (self->priv->process)
      {
      close (self->priv->from_compositor_pipe[0]);
      close (self->priv->from_compositor_pipe[1]);
      g_io_channel_unref (self->priv->from_compositor_channel);
 -    if (self->priv->from_compositor_watch)      
 +    if (self->priv->from_compositor_watch)
          g_source_remove (self->priv->from_compositor_watch);
      g_free (self->priv->read_buffer);
      if (self->priv->timeout_source)
diff --combined tests/Makefile.am
index c28f1a51e9cecca27241804bfb73c32545525bd1,d7778eb94c5d63b997bd1abe0ad75bb333e1cfa4..2f0087d3a3e3bb14c6c1575247fd5ec0859ec009
@@@ -187,6 -187,7 +187,7 @@@ TESTS = 
        test-multi-seat-non-graphical-disabled \
        test-multi-seat-change-graphical \
        test-multi-seat-change-graphical-disabled \
+       test-multi-seat-globbing-config-sections \
        test-mir-autologin \
        test-mir-greeter \
        test-mir-session \
        test-unity-login \
        test-unity-switch \
        test-unity-plymouth \
 +      test-unity-script-hooks \
        test-unity-mir-autologin \
        test-unity-mir-greeter-x-session \
        test-unity-mir-greeter-mir-session \
        test-unity-mir-lock-seat \
        test-unity-mir-session-x-greeter \
        test-unity-mir-switch \
 -      test-unity-mir-switch-to-user-resettable
 +      test-unity-mir-switch-to-user-resettable \
 +      test-unity-mir-script-hooks
  
 +#     test-mir-script-hooks \
  #     test-session-exit-error
  #     test-greeter-no-exit
  #   test-change-password-gobject
@@@ -449,7 -447,6 +450,7 @@@ EXTRA_DIST = 
        scripts/mir-autologin.conf \
        scripts/mir-container-session.conf \
        scripts/mir-greeter.conf \
 +      scripts/mir-script-hooks.conf \
        scripts/mir-session.conf \
        scripts/mir-session-compositor-crash.conf \
        scripts/mir-session-crash.conf \
        scripts/multi-seat-non-graphical-disabled.conf \
        scripts/multi-seat-seat0-non-graphical.conf \
        scripts/multi-seat-seat0-non-graphical-disabled.conf \
+       scripts/multi-seat-globbing-config-sections.conf \
        scripts/no-accounts-service.conf \
        scripts/no-config.conf \
        scripts/no-console-kit.conf \
        scripts/unity-mir-greeter-mir-session.conf \
        scripts/unity-mir-lock-seat.conf \
        scripts/unity-mir-greeter-x-session.conf \
 +      scripts/unity-mir-script-hooks.conf \
        scripts/unity-mir-session-x-greeter.conf \
        scripts/unity-mir-switch.conf \
        scripts/unity-mir-switch-to-user-resettable.conf \
        scripts/unity-plymouth.conf \
 +      scripts/unity-script-hooks.conf \
        scripts/unity-switch.conf \
        scripts/upstart-autologin.conf \
        scripts/upstart-login.conf \