[gdm/wip/wayland-rebase: 2/13] gdm-session: Remove some code duplication



commit f4a96eceddbe0e1feb098f871b87b0afc886abc3
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Feb 11 15:47:13 2014 -0500

    gdm-session: Remove some code duplication
    
    Move the keyfile loading to one place.

 daemon/gdm-session.c |   54 +++++++++++++++++++++++++------------------------
 1 files changed, 28 insertions(+), 26 deletions(-)
---
diff --git a/daemon/gdm-session.c b/daemon/gdm-session.c
index 8d6583c..fa727a4 100644
--- a/daemon/gdm-session.c
+++ b/daemon/gdm-session.c
@@ -381,22 +381,13 @@ is_prog_in_path (const char *prog)
         return ret;
 }
 
-static gboolean
-get_session_command_for_file (const char *file,
-                              char      **command)
+static GKeyFile *
+load_key_file_for_file (const char *file)
 {
         GKeyFile   *key_file;
         GError     *error;
-        char       *exec;
-        gboolean    ret;
         gboolean    res;
 
-        exec = NULL;
-        ret = FALSE;
-        if (command != NULL) {
-                *command = NULL;
-        }
-
         key_file = g_key_file_new ();
 
         g_debug ("GdmSession: looking for session file '%s'", file);
@@ -411,9 +402,31 @@ get_session_command_for_file (const char *file,
         if (! res) {
                 g_debug ("GdmSession: File '%s' not found: %s", file, error->message);
                 g_error_free (error);
-                if (command != NULL) {
-                        *command = NULL;
-                }
+                g_key_file_free (key_file);
+                key_file = NULL;
+        }
+
+        return key_file;
+}
+
+static gboolean
+get_session_command_for_file (const char *file,
+                              char      **command)
+{
+        GKeyFile   *key_file;
+        GError     *error;
+        char       *exec;
+        gboolean    ret;
+        gboolean    res;
+
+        exec = NULL;
+        ret = FALSE;
+        if (command != NULL) {
+                *command = NULL;
+        }
+
+        key_file = load_key_file_for_file (file);
+        if (key_file == NULL) {
                 goto out;
         }
 
@@ -2649,18 +2662,7 @@ gdm_session_bypasses_xsession (GdmSession *self)
 
         filename = g_strdup_printf ("%s.desktop", get_session_name (self));
 
-        key_file = g_key_file_new ();
-        error = NULL;
-        res = g_key_file_load_from_dirs (key_file,
-                                         filename,
-                                         get_system_session_dirs (),
-                                         NULL,
-                                         G_KEY_FILE_NONE,
-                                         &error);
-        if (! res) {
-                g_debug ("GdmSession: File '%s' not found: %s", filename, error->message);
-                goto out;
-        }
+        key_file = load_key_file_for_file (filename);
 
         error = NULL;
         res = g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-GDM-BypassXsession", NULL);


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