Blame SOURCES/classic-session.patch

7a4ca4
From 45848cf2625eaec34a07c03fdee624c8a2cb76de Mon Sep 17 00:00:00 2001
f3033d
From: Ray Strode <rstrode@redhat.com>
f3033d
Date: Wed, 3 Apr 2013 10:28:09 -0400
7a4ca4
Subject: [PATCH 8/8] session: change default session
f3033d
1e501a
We default to gnome-classic in rhel, unless overridden
1e501a
by /etc/sysconfig/desktop
f3033d
---
1e501a
 daemon/gdm-session.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++
1e501a
 1 file changed, 100 insertions(+)
f3033d
f3033d
diff --git a/daemon/gdm-session.c b/daemon/gdm-session.c
7a4ca4
index f62f77d0..d6f1e121 100644
f3033d
--- a/daemon/gdm-session.c
f3033d
+++ b/daemon/gdm-session.c
7a4ca4
@@ -495,76 +495,176 @@ get_session_command_for_name (GdmSession  *self,
7a4ca4
 {
75a7a3
         gboolean res;
75a7a3
         char    *filename;
75a7a3
 
75a7a3
         filename = g_strdup_printf ("%s.desktop", name);
75a7a3
         res = get_session_command_for_file (self, filename, command);
75a7a3
         g_free (filename);
75a7a3
 
75a7a3
         return res;
75a7a3
 }
75a7a3
 
75a7a3
 static const char *
75a7a3
 get_default_language_name (GdmSession *self)
75a7a3
 {
75a7a3
     const char *default_language;
75a7a3
 
75a7a3
     if (self->priv->saved_language != NULL) {
75a7a3
             return self->priv->saved_language;
75a7a3
     }
75a7a3
 
75a7a3
     default_language = g_hash_table_lookup (self->priv->environment,
75a7a3
                                             "LANG");
75a7a3
 
75a7a3
     if (default_language != NULL) {
75a7a3
             return default_language;
75a7a3
     }
75a7a3
 
75a7a3
     return setlocale (LC_MESSAGES, NULL);
f3033d
 }
1e501a
 
7a4ca4
+static const char *
1e501a
+get_configured_default_session_name (GdmSession *self)
1e501a
+{
1e501a
+        static const char *config_file = "/etc/sysconfig/desktop";
1e501a
+        const char    *session_name = "gnome-classic";
1e501a
+        gchar         *contents = NULL;
1e501a
+        gchar         *p;
1e501a
+        gsize          length;
1e501a
+        GError        *error;
1e501a
+        GString       *line;
1e501a
+        GRegex        *re;
1e501a
+
1e501a
+        if (!g_file_test (config_file, G_FILE_TEST_EXISTS)) {
1e501a
+                g_debug ("Cannot access '%s'", config_file);
1e501a
+                return session_name;
1e501a
+        }
1e501a
+
1e501a
+        error = NULL;
1e501a
+        if (!g_file_get_contents (config_file, &contents, &length, &error)) {
1e501a
+                g_debug ("Failed to parse '%s': %s",
1e501a
+                         config_file,
1e501a
+                         (error && error->message) ? error->message : "(null)");
1e501a
+                g_error_free (error);
1e501a
+                return session_name;
1e501a
+        }
1e501a
+
1e501a
+        if (!g_utf8_validate (contents, length, NULL)) {
1e501a
+                g_warning ("Invalid UTF-8 in '%s'", config_file);
1e501a
+                g_free (contents);
1e501a
+                return session_name;
1e501a
+        }
1e501a
+
1e501a
+        re = g_regex_new ("DESKTOP=\"?KDE\"?[ \t]*", 0, 0, &error);
1e501a
+        if (re == NULL) {
1e501a
+                g_warning ("Failed to regex: %s",
1e501a
+                           (error && error->message) ? error->message : "(null)");
1e501a
+                g_error_free (error);
1e501a
+                g_free (contents);
1e501a
+                return session_name;
1e501a
+        }
1e501a
+
1e501a
+        line = g_string_new ("");
1e501a
+        for (p = contents; p && *p; p = g_utf8_find_next_char (p, NULL)) {
1e501a
+                gunichar ch;
1e501a
+                GMatchInfo *match_info = NULL;
1e501a
+
1e501a
+                ch = g_utf8_get_char (p);
1e501a
+                if ((ch != '\n') && (ch != '\0')) {
1e501a
+                        g_string_append_unichar (line, ch);
1e501a
+                        continue;
1e501a
+                }
1e501a
+
1e501a
+                if (line->str && g_utf8_get_char (line->str) == '#') {
1e501a
+                        goto next_line;
1e501a
+                }
1e501a
+
1e501a
+                if (!g_regex_match (re, line->str, 0, &match_info)) {
1e501a
+                        goto next_line;
1e501a
+                }
1e501a
+
1e501a
+                if (!g_match_info_matches (match_info)) {
1e501a
+                        goto next_line;
1e501a
+                }
1e501a
+
1e501a
+                session_name = "1-kde-plasma-standard";
1e501a
+                break;
1e501a
+
1e501a
+next_line:
1e501a
+                g_match_info_free (match_info);
1e501a
+                g_string_set_size (line, 0);
1e501a
+        }
1e501a
+
1e501a
+        g_string_free (line, TRUE);
1e501a
+        g_regex_unref (re);
1e501a
+        g_free (contents);
1e501a
+
1e501a
+        return session_name;
1e501a
+}
1e501a
+
7a4ca4
 static const char *
f3033d
 get_fallback_session_name (GdmSession *self)
f3033d
 {
7a4ca4
         char          **search_dirs;
1e501a
+        const char     *configured_session;
f3033d
         int             i;
f3033d
         char           *name;
f3033d
         GSequence      *sessions;
75a7a3
         GSequenceIter  *session;
75a7a3
 
75a7a3
         if (self->priv->fallback_session_name != NULL) {
75a7a3
                 /* verify that the cached version still exists */
75a7a3
                 if (get_session_command_for_name (self, self->priv->fallback_session_name, NULL)) {
75a7a3
                         goto out;
f3033d
                 }
f3033d
         }
1e501a
 
1e501a
+        configured_session = get_configured_default_session_name (self);
1e501a
+
1e501a
+        name = g_strdup (configured_session);
75a7a3
+        if (get_session_command_for_name (self, name, NULL)) {
f3033d
+                g_free (self->priv->fallback_session_name);
f3033d
+                self->priv->fallback_session_name = name;
f3033d
+                goto out;
f3033d
+        }
f3033d
+        g_free (name);
f3033d
+
1e501a
+        if (g_strcmp0 (configured_session, "gnome-classic") != 0) {
1e501a
+                name = g_strdup ("gnome-classic");
75a7a3
+                if (get_session_command_for_name (self, name, NULL)) {
1e501a
+                        g_free (self->priv->fallback_session_name);
1e501a
+                        self->priv->fallback_session_name = name;
1e501a
+                        goto out;
1e501a
+                }
1e501a
+                g_free (name);
1e501a
+        }
1e501a
+
f3033d
         name = g_strdup ("gnome");
75a7a3
         if (get_session_command_for_name (self, name, NULL)) {
f3033d
                 g_free (self->priv->fallback_session_name);
75a7a3
                 self->priv->fallback_session_name = name;
75a7a3
                 goto out;
75a7a3
         }
75a7a3
         g_free (name);
75a7a3
 
75a7a3
         sessions = g_sequence_new (g_free);
75a7a3
 
75a7a3
         search_dirs = get_system_session_dirs (self);
75a7a3
         for (i = 0; search_dirs[i] != NULL; i++) {
75a7a3
                 GDir       *dir;
75a7a3
                 const char *base_name;
75a7a3
 
75a7a3
                 dir = g_dir_open (search_dirs[i], 0, NULL);
75a7a3
 
75a7a3
                 if (dir == NULL) {
75a7a3
                         continue;
75a7a3
                 }
75a7a3
 
75a7a3
                 do {
75a7a3
                         base_name = g_dir_read_name (dir);
75a7a3
 
75a7a3
                         if (base_name == NULL) {
75a7a3
                                 break;
75a7a3
                         }
75a7a3
 
75a7a3
                         if (!g_str_has_suffix (base_name, ".desktop")) {
75a7a3
                                 continue;
1e501a
-- 
7a4ca4
2.14.2
f3033d