[gdm] session: load locale.conf from gdm-session.c



commit cab736cfb32aa25677287ff261ae1cb11f036e89
Author: Ray Strode <rstrode redhat com>
Date:   Thu Jul 2 13:08:05 2015 -0400

    session: load locale.conf from gdm-session.c
    
    Right now we're not picking up changes to locale.conf completely
    at runtime.
    
    This commit moves reading locale.conf to a different place in the
    code, so that it's more effectively read and used.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751865

 daemon/gdm-launch-environment.c |  106 ---------------------------------------
 daemon/gdm-session.c            |   96 +++++++++++++++++++++++++++++++++++-
 2 files changed, 95 insertions(+), 107 deletions(-)
---
diff --git a/daemon/gdm-launch-environment.c b/daemon/gdm-launch-environment.c
index 4982f7c..ec29d90 100644
--- a/daemon/gdm-launch-environment.c
+++ b/daemon/gdm-launch-environment.c
@@ -110,109 +110,6 @@ static void     gdm_launch_environment_finalize      (GObject
 
 G_DEFINE_TYPE (GdmLaunchEnvironment, gdm_launch_environment, G_TYPE_OBJECT)
 
-static void
-load_lang_config_file (const char  *config_file,
-                       const char **str_array)
-{
-        gchar         *contents = NULL;
-        gchar         *p;
-        gchar         *str_joinv;
-        gchar         *pattern;
-        gchar         *key;
-        gchar         *value;
-        gsize          length;
-        GError        *error;
-        GString       *line;
-        GRegex        *re;
-
-        g_return_if_fail (config_file != NULL);
-        g_return_if_fail (str_array != NULL);
-
-        if (!g_file_test (config_file, G_FILE_TEST_EXISTS)) {
-                g_debug ("Cannot access '%s'", config_file);
-                return;
-        }
-
-        error = NULL;
-        if (!g_file_get_contents (config_file, &contents, &length, &error)) {
-                g_debug ("Failed to parse '%s': %s",
-                         config_file,
-                         (error && error->message) ? error->message : "(null)");
-                g_error_free (error);
-                return;
-        }
-
-        if (!g_utf8_validate (contents, length, NULL)) {
-                g_warning ("Invalid UTF-8 in '%s'", config_file);
-                g_free (contents);
-                return;
-        }
-
-        str_joinv = g_strjoinv ("|", (char **) str_array);
-        if (str_joinv == NULL) {
-                g_warning ("Error in joined");
-                g_free (contents);
-                return;
-        }
-
-        pattern = g_strdup_printf ("(?P<key>(%s))=(\")?(?P<value>[^\"]*)?(\")?",
-                                   str_joinv);
-        error = NULL;
-        re = g_regex_new (pattern, 0, 0, &error);
-        g_free (pattern);
-        g_free (str_joinv);
-        if (re == NULL) {
-                g_warning ("Failed to regex: %s",
-                           (error && error->message) ? error->message : "(null)");
-                g_error_free (error);
-                g_free (contents);
-                return;
-        }
-
-        line = g_string_new ("");
-        for (p = contents; p && *p; p = g_utf8_find_next_char (p, NULL)) {
-                gunichar ch;
-                GMatchInfo *match_info = NULL;
-
-                ch = g_utf8_get_char (p);
-                if ((ch != '\n') && (ch != '\0')) {
-                        g_string_append_unichar (line, ch);
-                        continue;
-                }
-
-                if (line->str && g_utf8_get_char (line->str) == '#') {
-                        goto next_line;
-                }
-
-                if (!g_regex_match (re, line->str, 0, &match_info)) {
-                        goto next_line;
-                }
-
-                if (!g_match_info_matches (match_info)) {
-                        goto next_line;
-                }
-
-                key = g_match_info_fetch_named (match_info, "key");
-                value = g_match_info_fetch_named (match_info, "value");
-
-                if (key && *key && value && *value) {
-                        g_setenv (key, value, TRUE);
-                } else if (key && *key) {
-                        g_unsetenv (key);
-                }
-
-                g_free (key);
-                g_free (value);
-next_line:
-                g_match_info_free (match_info);
-                g_string_set_size (line, 0);
-        }
-
-        g_string_free (line, TRUE);
-        g_regex_unref (re);
-        g_free (contents);
-}
-
 static GHashTable *
 build_launch_environment (GdmLaunchEnvironment *launch_environment,
                           gboolean              start_session)
@@ -229,9 +126,6 @@ build_launch_environment (GdmLaunchEnvironment *launch_environment,
         char *system_data_dirs;
         int i;
 
-        load_lang_config_file (LANG_CONFIG_FILE,
-                               (const char **) optional_environment);
-
         /* create a hash table of current environment, then update keys has necessary */
         hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
diff --git a/daemon/gdm-session.c b/daemon/gdm-session.c
index b64c3ed..6faa7cd 100644
--- a/daemon/gdm-session.c
+++ b/daemon/gdm-session.c
@@ -485,8 +485,17 @@ get_session_command_for_name (const char *name,
 static const char *
 get_default_language_name (GdmSession *self)
 {
+    const char *default_language;
+
     if (self->priv->saved_language != NULL) {
-                return self->priv->saved_language;
+            return self->priv->saved_language;
+    }
+
+    default_language = g_hash_table_lookup (self->priv->environment,
+                                            "LANG");
+
+    if (default_language != NULL) {
+            return default_language;
     }
 
     return setlocale (LC_MESSAGES, NULL);
@@ -1672,6 +1681,90 @@ free_conversation (GdmSessionConversation *conversation)
 }
 
 static void
+load_lang_config_file (GdmSession *self)
+{
+        static const char *config_file = LANG_CONFIG_FILE;
+        gchar         *contents = NULL;
+        gchar         *p;
+        gchar         *key;
+        gchar         *value;
+        gsize          length;
+        GError        *error;
+        GString       *line;
+        GRegex        *re;
+
+        if (!g_file_test (config_file, G_FILE_TEST_EXISTS)) {
+                g_debug ("Cannot access '%s'", config_file);
+                return;
+        }
+
+        error = NULL;
+        if (!g_file_get_contents (config_file, &contents, &length, &error)) {
+                g_debug ("Failed to parse '%s': %s",
+                         LANG_CONFIG_FILE,
+                         (error && error->message) ? error->message : "(null)");
+                g_error_free (error);
+                return;
+        }
+
+        if (!g_utf8_validate (contents, length, NULL)) {
+                g_warning ("Invalid UTF-8 in '%s'", config_file);
+                g_free (contents);
+                return;
+        }
+
+        re = g_regex_new 
("(?P<key>(LANG|LANGUAGE|LC_CTYPE|LC_NUMERIC|LC_TIME|LC_COLLATE|LC_MONETARY|LC_MESSAGES|LC_PAPER|LC_NAME|LC_ADDRESS|LC_TELEPHONE|LC_MEASUREMENT|LC_IDENTIFICATION|LC_ALL))=(\")?(?P<value>[^\"]*)?(\")?",
 0, 0, &error);
+        if (re == NULL) {
+                g_warning ("Failed to regex: %s",
+                           (error && error->message) ? error->message : "(null)");
+                g_error_free (error);
+                g_free (contents);
+                return;
+        }
+
+        line = g_string_new ("");
+        for (p = contents; p && *p; p = g_utf8_find_next_char (p, NULL)) {
+                gunichar ch;
+                GMatchInfo *match_info = NULL;
+
+                ch = g_utf8_get_char (p);
+                if ((ch != '\n') && (ch != '\0')) {
+                        g_string_append_unichar (line, ch);
+                        continue;
+                }
+
+                if (line->str && g_utf8_get_char (line->str) == '#') {
+                        goto next_line;
+                }
+
+                if (!g_regex_match (re, line->str, 0, &match_info)) {
+                        goto next_line;
+                }
+
+                if (!g_match_info_matches (match_info)) {
+                        goto next_line;
+                }
+
+                key = g_match_info_fetch_named (match_info, "key");
+                value = g_match_info_fetch_named (match_info, "value");
+
+                if (key && *key && value && *value) {
+                       g_setenv (key, value, TRUE);
+                }
+
+                g_free (key);
+                g_free (value);
+next_line:
+                g_match_info_free (match_info);
+                g_string_set_size (line, 0);
+        }
+
+        g_string_free (line, TRUE);
+        g_regex_unref (re);
+        g_free (contents);
+}
+
+static void
 gdm_session_init (GdmSession *self)
 {
         self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
@@ -1688,6 +1781,7 @@ gdm_session_init (GdmSession *self)
                                                          (GDestroyNotify) g_free,
                                                          (GDestroyNotify) g_free);
 
+        load_lang_config_file (self);
         setup_worker_server (self);
         setup_outside_server (self);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]