Blob Blame History Raw
From 45848cf2625eaec34a07c03fdee624c8a2cb76de Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Wed, 3 Apr 2013 10:28:09 -0400
Subject: [PATCH 8/8] session: change default session

We default to gnome-classic in rhel, unless overridden
by /etc/sysconfig/desktop
---
 daemon/gdm-session.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)

diff --git a/daemon/gdm-session.c b/daemon/gdm-session.c
index f62f77d0..d6f1e121 100644
--- a/daemon/gdm-session.c
+++ b/daemon/gdm-session.c
@@ -495,76 +495,176 @@ get_session_command_for_name (GdmSession  *self,
 {
         gboolean res;
         char    *filename;
 
         filename = g_strdup_printf ("%s.desktop", name);
         res = get_session_command_for_file (self, filename, command);
         g_free (filename);
 
         return res;
 }
 
 static const char *
 get_default_language_name (GdmSession *self)
 {
     const char *default_language;
 
     if (self->priv->saved_language != NULL) {
             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);
 }
 
+static const char *
+get_configured_default_session_name (GdmSession *self)
+{
+        static const char *config_file = "/etc/sysconfig/desktop";
+        const char    *session_name = "gnome-classic";
+        gchar         *contents = NULL;
+        gchar         *p;
+        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 session_name;
+        }
+
+        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 session_name;
+        }
+
+        if (!g_utf8_validate (contents, length, NULL)) {
+                g_warning ("Invalid UTF-8 in '%s'", config_file);
+                g_free (contents);
+                return session_name;
+        }
+
+        re = g_regex_new ("DESKTOP=\"?KDE\"?[ \t]*", 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 session_name;
+        }
+
+        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;
+                }
+
+                session_name = "1-kde-plasma-standard";
+                break;
+
+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);
+
+        return session_name;
+}
+
 static const char *
 get_fallback_session_name (GdmSession *self)
 {
         char          **search_dirs;
+        const char     *configured_session;
         int             i;
         char           *name;
         GSequence      *sessions;
         GSequenceIter  *session;
 
         if (self->priv->fallback_session_name != NULL) {
                 /* verify that the cached version still exists */
                 if (get_session_command_for_name (self, self->priv->fallback_session_name, NULL)) {
                         goto out;
                 }
         }
 
+        configured_session = get_configured_default_session_name (self);
+
+        name = g_strdup (configured_session);
+        if (get_session_command_for_name (self, name, NULL)) {
+                g_free (self->priv->fallback_session_name);
+                self->priv->fallback_session_name = name;
+                goto out;
+        }
+        g_free (name);
+
+        if (g_strcmp0 (configured_session, "gnome-classic") != 0) {
+                name = g_strdup ("gnome-classic");
+                if (get_session_command_for_name (self, name, NULL)) {
+                        g_free (self->priv->fallback_session_name);
+                        self->priv->fallback_session_name = name;
+                        goto out;
+                }
+                g_free (name);
+        }
+
         name = g_strdup ("gnome");
         if (get_session_command_for_name (self, name, NULL)) {
                 g_free (self->priv->fallback_session_name);
                 self->priv->fallback_session_name = name;
                 goto out;
         }
         g_free (name);
 
         sessions = g_sequence_new (g_free);
 
         search_dirs = get_system_session_dirs (self);
         for (i = 0; search_dirs[i] != NULL; i++) {
                 GDir       *dir;
                 const char *base_name;
 
                 dir = g_dir_open (search_dirs[i], 0, NULL);
 
                 if (dir == NULL) {
                         continue;
                 }
 
                 do {
                         base_name = g_dir_read_name (dir);
 
                         if (base_name == NULL) {
                                 break;
                         }
 
                         if (!g_str_has_suffix (base_name, ".desktop")) {
                                 continue;
-- 
2.14.2