[gdm: 1/2] Search sessions in XDG_DATA_DIRS



commit 385b9c22b638793403a734a5e3bf34406491c0e6
Author: Jan Tojnar <jtojnar gmail com>
Date:   Sat Aug 4 15:26:53 2018 +0200

    Search sessions in XDG_DATA_DIRS

 daemon/gdm-session.c  | 17 +++++++++++++++++
 libgdm/gdm-sessions.c | 36 ++++++++++++++++++++++++++++++++----
 2 files changed, 49 insertions(+), 4 deletions(-)
---
diff --git a/daemon/gdm-session.c b/daemon/gdm-session.c
index 19d26c92..600da0f3 100644
--- a/daemon/gdm-session.c
+++ b/daemon/gdm-session.c
@@ -343,6 +343,8 @@ get_system_session_dirs (GdmSession *self)
 {
         GArray *search_array = NULL;
         char **search_dirs;
+        int i;
+        const gchar * const *system_data_dirs = g_get_system_data_dirs ();
 
         static const char *x_search_dirs[] = {
                 "/etc/X11/sessions/",
@@ -355,13 +357,28 @@ get_system_session_dirs (GdmSession *self)
 
         search_array = g_array_new (TRUE, TRUE, sizeof (char *));
 
+        for (i = 0; system_data_dirs[i]; i++) {
+                gchar *dir = g_build_filename (system_data_dirs[i], "xsessions", NULL);
+                g_array_append_val (search_array, dir);
+        }
+
         g_array_append_vals (search_array, x_search_dirs, G_N_ELEMENTS (x_search_dirs));
 
 #ifdef ENABLE_WAYLAND_SUPPORT
         if (!self->priv->ignore_wayland) {
 #ifdef ENABLE_USER_DISPLAY_SERVER
                 g_array_prepend_val (search_array, wayland_search_dir);
+
+                for (i = 0; system_data_dirs[i]; i++) {
+                        gchar *dir = g_build_filename (system_data_dirs[i], "wayland-sessions", NULL);
+                        g_array_insert_val (search_array, i, dir);
+                }
 #else
+                for (i = 0; system_data_dirs[i]; i++) {
+                        gchar *dir = g_build_filename (system_data_dirs[i], "wayland-sessions", NULL);
+                        g_array_append_val (search_array, dir);
+                }
+
                 g_array_append_val (search_array, wayland_search_dir);
 #endif
         }
diff --git a/libgdm/gdm-sessions.c b/libgdm/gdm-sessions.c
index 8bf7bd75..7badafe1 100644
--- a/libgdm/gdm-sessions.c
+++ b/libgdm/gdm-sessions.c
@@ -215,6 +215,9 @@ collect_sessions_from_directory (const char *dirname)
 static void
 collect_sessions (void)
 {
+        GArray     *xorg_search_array = NULL;
+        GArray     *wayland_search_array = NULL;
+        gchar      *session_dir = NULL;
         int         i;
         const char *xorg_search_dirs[] = {
                 "/etc/X11/sessions/",
@@ -224,11 +227,31 @@ collect_sessions (void)
                 NULL
         };
 
+        xorg_search_array = g_array_new (TRUE, TRUE, sizeof (char *));
+
+        const gchar * const *system_data_dirs = g_get_system_data_dirs ();
+
+        for (i = 0; system_data_dirs[i]; i++) {
+                session_dir = g_build_filename (system_data_dirs[i], "xsessions", NULL);
+                g_array_append_val (xorg_search_array, session_dir);
+        }
+
+        g_array_append_vals (xorg_search_array, xorg_search_dirs, G_N_ELEMENTS (xorg_search_dirs));
+
 #ifdef ENABLE_WAYLAND_SUPPORT
         const char *wayland_search_dirs[] = {
                 DATADIR "/wayland-sessions/",
                 NULL
         };
+
+        wayland_search_array = g_array_new (TRUE, TRUE, sizeof (char *));
+
+        for (i = 0; system_data_dirs[i]; i++) {
+                session_dir = g_build_filename (system_data_dirs[i], "wayland-sessions", NULL);
+                g_array_append_val (wayland_search_array, session_dir);
+        }
+
+        g_array_append_vals (wayland_search_array, wayland_search_dirs, G_N_ELEMENTS (wayland_search_dirs));
 #endif
 
         if (gdm_available_sessions_map == NULL) {
@@ -236,20 +259,25 @@ collect_sessions (void)
                                                                     g_free, 
(GDestroyNotify)gdm_session_file_free);
         }
 
-        for (i = 0; xorg_search_dirs [i] != NULL; i++) {
-                collect_sessions_from_directory (xorg_search_dirs [i]);
+        for (i = 0; i < xorg_search_array->len; i++) {
+                collect_sessions_from_directory (g_array_index (xorg_search_array, gchar*, i));
         }
 
+        g_array_free (xorg_search_array, TRUE);
+
 #ifdef ENABLE_WAYLAND_SUPPORT
 #ifdef ENABLE_USER_DISPLAY_SERVER
         if (g_getenv ("WAYLAND_DISPLAY") == NULL && g_getenv ("RUNNING_UNDER_GDM") != NULL) {
+                g_array_free (wayland_search_array, TRUE);
                 return;
         }
 #endif
 
-        for (i = 0; wayland_search_dirs [i] != NULL; i++) {
-                collect_sessions_from_directory (wayland_search_dirs [i]);
+        for (i = 0; i < wayland_search_array->len; i++) {
+                collect_sessions_from_directory (g_array_index (wayland_search_array, gchar*, i));
         }
+
+        g_array_free (wayland_search_array, TRUE);
 #endif
 }
 


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