liblightdm-gobject/session.c | 49 +++++++++++++++++++++---- tests/Makefile.am | 4 ++ tests/data/other-sessions/alternative-2.desktop | 4 ++ tests/data/other-sessions/named-2.desktop | 5 +++ tests/data/other-sessions/wayland-2.desktop | 5 +++ tests/data/sessions/default.desktop | 4 +- tests/data/sessions/mir.desktop | 2 +- tests/data/sessions/named-legacy.desktop | 4 +- tests/data/sessions/named.desktop | 4 +- tests/data/sessions/wayland.desktop | 2 +- tests/scripts/session-sort-01.conf | 47 ++++++++++++++++++++++++ tests/scripts/session-sort-02.conf | 47 ++++++++++++++++++++++++ tests/scripts/sessions.conf | 4 +- tests/src/test-gobject-greeter.c | 19 ++++++---- tests/src/test-python-greeter | 1 - tests/src/test-qt-greeter.cpp | 1 - tests/src/test-runner.c | 3 ++ tests/test-session-sort-01 | 2 + tests/test-session-sort-02 | 2 + 19 files changed, 183 insertions(+), 26 deletions(-) diff --git a/liblightdm-gobject/session.c b/liblightdm-gobject/session.c index 79dcf466..fbe513d4 100644 --- a/liblightdm-gobject/session.c +++ b/liblightdm-gobject/session.c @@ -47,6 +47,7 @@ typedef struct gchar *type; gchar *name; gchar *comment; + gchar *directory; } LightDMSessionPrivate; G_DEFINE_TYPE_WITH_PRIVATE (LightDMSession, lightdm_session, G_TYPE_OBJECT) @@ -56,13 +57,39 @@ static GList *local_sessions = NULL; static GList *remote_sessions = NULL; static gint -compare_session (gconstpointer a, gconstpointer b) +dir_number (const gchar *dir, const gchar *dir_list) { - return strcmp (lightdm_session_get_name (LIGHTDM_SESSION (a)), lightdm_session_get_name (LIGHTDM_SESSION (b))); + g_auto(GStrv) dirs = g_strsplit ((const gchar *) dir_list, ":", -1); + + int i = 0; + for (; dirs[i]; i++) + { + if (0 == strcmp (dir, dirs[i])) + return i; + } + + return i; +} + +static gint +compare_session (gconstpointer a, gconstpointer b, gpointer dir_list) +{ + LightDMSessionPrivate *priv_a = lightdm_session_get_instance_private (LIGHTDM_SESSION (a)); + LightDMSessionPrivate *priv_b = lightdm_session_get_instance_private (LIGHTDM_SESSION (b)); + + const gchar *_dir_list = (const gchar *) dir_list; + + int dir_a = dir_number (priv_a->directory, _dir_list); + int dir_b = dir_number (priv_b->directory, _dir_list); + + if (dir_a != dir_b) + return dir_a - dir_b; + else + return strcmp (priv_a->name, priv_b->name); } static LightDMSession * -load_session (GKeyFile *key_file, const gchar *key, const gchar *default_type) +load_session (GKeyFile *key_file, const gchar *key, const gchar *default_type, const gchar *sessions_dir) { if (g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, NULL) || g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_HIDDEN, NULL)) @@ -109,11 +136,14 @@ load_session (GKeyFile *key_file, const gchar *key, const gchar *default_type) if (!priv->comment) priv->comment = g_strdup (""); + g_free (priv->directory); + priv->directory = g_strdup (sessions_dir); + return session; } static GList * -load_sessions_dir (GList *sessions, const gchar *sessions_dir, const gchar *default_type) +load_sessions_dir (GList *sessions, const gchar *sessions_dir, const gchar *default_type, const gchar *dir_list) { g_autoptr(GError) error = NULL; GDir *directory = g_dir_open (sessions_dir, 0, &error); @@ -122,6 +152,8 @@ load_sessions_dir (GList *sessions, const gchar *sessions_dir, const gchar *defa if (!directory) return sessions; + g_autofree gchar *_dir_list = g_strdup (dir_list); + while (TRUE) { const gchar *filename = g_dir_read_name (directory); @@ -142,12 +174,13 @@ load_sessions_dir (GList *sessions, const gchar *sessions_dir, const gchar *defa if (result) { g_autofree gchar *key = g_strndup (filename, strlen (filename) - strlen (".desktop")); - LightDMSession *session = load_session (key_file, key, default_type); + + LightDMSession *session = load_session (key_file, key, default_type, sessions_dir); LightDMSessionPrivate *priv = lightdm_session_get_instance_private (session); if (session) { g_debug ("Loaded session %s (%s, %s)", path, priv->name, priv->comment); - sessions = g_list_insert_sorted (sessions, session, compare_session); + sessions = g_list_insert_sorted_with_data (sessions, session, compare_session, _dir_list); } else g_debug ("Ignoring session %s", path); @@ -171,7 +204,8 @@ load_sessions (const gchar *sessions_dir) if (dirs[i] != NULL && g_str_has_suffix (dirs[i], "/wayland-sessions") == TRUE) default_type = "wayland"; - sessions = load_sessions_dir (sessions, dirs[i], default_type); + sessions = load_sessions_dir (sessions, dirs[i], default_type, + sessions_dir); } return sessions; @@ -353,6 +387,7 @@ lightdm_session_finalize (GObject *object) g_free (priv->type); g_free (priv->name); g_free (priv->comment); + g_free (priv->directory); } static void diff --git a/tests/Makefile.am b/tests/Makefile.am index 1002c834..d34ed5a8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -74,6 +74,8 @@ TESTS = \ test-corrupt-xauthority \ test-system-xauthority \ test-sessions-gobject \ + test-session-sort-01 \ + test-session-sort-02 \ test-user-renamed \ test-user-renamed-invalid \ test-user-name \ @@ -509,6 +511,8 @@ EXTRA_DIST = \ scripts/script-hook-session-setup-missing.conf \ scripts/seatdefaults-still-supported.conf \ scripts/sessions.conf \ + scripts/session-sort-01.conf \ + scripts/session-sort-02.conf \ scripts/session-greeter.conf \ scripts/session-greeter-allow-guest.conf \ scripts/session-greeter-autologin.conf \ diff --git a/tests/data/other-sessions/alternative-2.desktop b/tests/data/other-sessions/alternative-2.desktop new file mode 100644 index 00000000..9bf3074b --- /dev/null +++ b/tests/data/other-sessions/alternative-2.desktop @@ -0,0 +1,4 @@ +[Desktop Entry] +Name=Another Alternative Test Session +Comment=Another LightDM alternative test session +Exec=test-session alternative-2 diff --git a/tests/data/other-sessions/named-2.desktop b/tests/data/other-sessions/named-2.desktop new file mode 100644 index 00000000..70b600b4 --- /dev/null +++ b/tests/data/other-sessions/named-2.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Test Session 2 +Comment=LightDM test session number 2 +Exec=test-session named-2 +DesktopNames=TestDesktop3;TestDesktop4; diff --git a/tests/data/other-sessions/wayland-2.desktop b/tests/data/other-sessions/wayland-2.desktop new file mode 100644 index 00000000..acda61c7 --- /dev/null +++ b/tests/data/other-sessions/wayland-2.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Test Wayland Session 2 +Comment=LightDM test Wayland session number 2 +Exec=test-session wayland-2 +X-LightDM-Session-Type=wayland diff --git a/tests/data/sessions/default.desktop b/tests/data/sessions/default.desktop index 9e451a56..c6b456d7 100644 --- a/tests/data/sessions/default.desktop +++ b/tests/data/sessions/default.desktop @@ -1,4 +1,4 @@ [Desktop Entry] -Name=Test Session -Comment=LightDM test session +Name=Default Test Session +Comment=LightDM default test session Exec=test-session diff --git a/tests/data/sessions/mir.desktop b/tests/data/sessions/mir.desktop index afa9d591..06d9887f 100644 --- a/tests/data/sessions/mir.desktop +++ b/tests/data/sessions/mir.desktop @@ -1,5 +1,5 @@ [Desktop Entry] -Name=Test Session +Name=Mir Test Session Comment=LightDM test Mir session Exec=test-session X-LightDM-Session-Type=mir diff --git a/tests/data/sessions/named-legacy.desktop b/tests/data/sessions/named-legacy.desktop index 3c0870d7..f7455cca 100644 --- a/tests/data/sessions/named-legacy.desktop +++ b/tests/data/sessions/named-legacy.desktop @@ -1,5 +1,5 @@ [Desktop Entry] -Name=Test Session -Comment=LightDM test session +Name=Legacy Named Test Session +Comment=A LightDM legacy named test session Exec=test-session X-LightDM-DesktopName=TestDesktop diff --git a/tests/data/sessions/named.desktop b/tests/data/sessions/named.desktop index bab172f5..706b80df 100644 --- a/tests/data/sessions/named.desktop +++ b/tests/data/sessions/named.desktop @@ -1,5 +1,5 @@ [Desktop Entry] -Name=Test Session -Comment=LightDM test session +Name=Named Test Session +Comment=A named LightDM test session Exec=test-session DesktopNames=TestDesktop1;TestDesktop2; diff --git a/tests/data/sessions/wayland.desktop b/tests/data/sessions/wayland.desktop index 2eb55d16..96abbb79 100644 --- a/tests/data/sessions/wayland.desktop +++ b/tests/data/sessions/wayland.desktop @@ -1,5 +1,5 @@ [Desktop Entry] -Name=Test Session +Name=Wayland Test Session Comment=LightDM test Wayland session Exec=test-session X-LightDM-Session-Type=wayland diff --git a/tests/scripts/session-sort-01.conf b/tests/scripts/session-sort-01.conf new file mode 100644 index 00000000..717a5661 --- /dev/null +++ b/tests/scripts/session-sort-01.conf @@ -0,0 +1,47 @@ + +# Checks that session keys depend on the directory order in sessions-directory +# (other-sessions second). + +[LightDM] +sessions-directory=/usr/share/lightdm/sessions:/usr/share/lightdm/other-sessions + +[Seat:*] +user-session=default + +#?*START-DAEMON +#?RUNNER DAEMON-START + +# X server starts +#?XSERVER-0 START VT=7 SEAT=seat0 + +# Daemon connects when X server is ready +#?*XSERVER-0 INDICATE-READY +#?XSERVER-0 INDICATE-READY +#?XSERVER-0 ACCEPT-CONNECT + +# Greeter starts +#?GREETER-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_SESSION_CLASS=greeter +#?LOGIN1 ACTIVATE-SESSION SESSION=c0 +#?XSERVER-0 ACCEPT-CONNECT +#?GREETER-X-0 CONNECT-XSERVER +#?GREETER-X-0 CONNECT-TO-DAEMON +#?GREETER-X-0 CONNECTED-TO-DAEMON + +# List sessions +#?*GREETER-X-0 LOG-SESSIONS +#?GREETER-X-0 LOG-SESSION KEY=alternative +#?GREETER-X-0 LOG-SESSION KEY=default +#?GREETER-X-0 LOG-SESSION KEY=named-legacy +#?GREETER-X-0 LOG-SESSION KEY=mir +#?GREETER-X-0 LOG-SESSION KEY=named +#?GREETER-X-0 LOG-SESSION KEY=greeter +#?GREETER-X-0 LOG-SESSION KEY=wayland +#?GREETER-X-0 LOG-SESSION KEY=alternative-2 +#?GREETER-X-0 LOG-SESSION KEY=named-2 +#?GREETER-X-0 LOG-SESSION KEY=wayland-2 + +# Cleanup +#?*STOP-DAEMON +#?GREETER-X-0 TERMINATE SIGNAL=15 +#?XSERVER-0 TERMINATE SIGNAL=15 +#?RUNNER DAEMON-EXIT STATUS=0 diff --git a/tests/scripts/session-sort-02.conf b/tests/scripts/session-sort-02.conf new file mode 100644 index 00000000..5d2ca940 --- /dev/null +++ b/tests/scripts/session-sort-02.conf @@ -0,0 +1,47 @@ + +# Checks that session keys depend on the directory order in sessions-directory +# (other-sessions first). + +[LightDM] +sessions-directory=/usr/share/lightdm/other-sessions:/usr/share/lightdm/sessions + +[Seat:*] +user-session=default + +#?*START-DAEMON +#?RUNNER DAEMON-START + +# X server starts +#?XSERVER-0 START VT=7 SEAT=seat0 + +# Daemon connects when X server is ready +#?*XSERVER-0 INDICATE-READY +#?XSERVER-0 INDICATE-READY +#?XSERVER-0 ACCEPT-CONNECT + +# Greeter starts +#?GREETER-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_SESSION_CLASS=greeter +#?LOGIN1 ACTIVATE-SESSION SESSION=c0 +#?XSERVER-0 ACCEPT-CONNECT +#?GREETER-X-0 CONNECT-XSERVER +#?GREETER-X-0 CONNECT-TO-DAEMON +#?GREETER-X-0 CONNECTED-TO-DAEMON + +# List sessions +#?*GREETER-X-0 LOG-SESSIONS +#?GREETER-X-0 LOG-SESSION KEY=alternative-2 +#?GREETER-X-0 LOG-SESSION KEY=named-2 +#?GREETER-X-0 LOG-SESSION KEY=wayland-2 +#?GREETER-X-0 LOG-SESSION KEY=alternative +#?GREETER-X-0 LOG-SESSION KEY=default +#?GREETER-X-0 LOG-SESSION KEY=named-legacy +#?GREETER-X-0 LOG-SESSION KEY=mir +#?GREETER-X-0 LOG-SESSION KEY=named +#?GREETER-X-0 LOG-SESSION KEY=greeter +#?GREETER-X-0 LOG-SESSION KEY=wayland + +# Cleanup +#?*STOP-DAEMON +#?GREETER-X-0 TERMINATE SIGNAL=15 +#?XSERVER-0 TERMINATE SIGNAL=15 +#?RUNNER DAEMON-EXIT STATUS=0 diff --git a/tests/scripts/sessions.conf b/tests/scripts/sessions.conf index 95a1b7db..47256841 100644 --- a/tests/scripts/sessions.conf +++ b/tests/scripts/sessions.conf @@ -28,10 +28,10 @@ user-session=default #?*GREETER-X-0 LOG-SESSIONS #?GREETER-X-0 LOG-SESSION KEY=alternative #?GREETER-X-0 LOG-SESSION KEY=default -#?GREETER-X-0 LOG-SESSION KEY=greeter +#?GREETER-X-0 LOG-SESSION KEY=named-legacy #?GREETER-X-0 LOG-SESSION KEY=mir #?GREETER-X-0 LOG-SESSION KEY=named -#?GREETER-X-0 LOG-SESSION KEY=named-legacy +#?GREETER-X-0 LOG-SESSION KEY=greeter #?GREETER-X-0 LOG-SESSION KEY=wayland # Cleanup diff --git a/tests/src/test-gobject-greeter.c b/tests/src/test-gobject-greeter.c index 54fff9a9..6b174608 100644 --- a/tests/src/test-gobject-greeter.c +++ b/tests/src/test-gobject-greeter.c @@ -166,12 +166,6 @@ read_shared_data_finished (GObject *object, GAsyncResult *result, gpointer data) status_notify ("%s READ-SHARED-DATA ERROR=%s", greeter_id, error->message); } -static int -compare_session (gconstpointer a, gconstpointer b) -{ - return strcmp (lightdm_session_get_key (LIGHTDM_SESSION (a)), lightdm_session_get_key (LIGHTDM_SESSION (b))); -} - static void request_cb (const gchar *name, GHashTable *params) { @@ -318,7 +312,6 @@ request_cb (const gchar *name, GHashTable *params) else if (strcmp (name, "LOG-SESSIONS") == 0) { GList *sessions = lightdm_get_sessions (); - sessions = g_list_sort (sessions, compare_session); for (GList *link = sessions; link; link = link->next) { LightDMSession *session = link->data; @@ -377,6 +370,18 @@ request_cb (const gchar *name, GHashTable *params) if (!lightdm_shutdown (&error)) status_notify ("%s FAIL-SHUTDOWN", greeter_id); } + + else if (strcmp (name, "SET-LANGUAGE") == 0) + { + if (g_hash_table_lookup (params, "VALUE")) + { + g_autoptr(GError) error = NULL; + if (lightdm_greeter_set_language (greeter, g_hash_table_lookup (params, "VALUE"), &error)) + status_notify ("%s SET-LANGUAGE OK", greeter_id); + else + status_notify ("%s SET-LANGUAGE ERROR=%s", greeter_id, error->message); + } + } } static void diff --git a/tests/src/test-python-greeter b/tests/src/test-python-greeter index ece57c47..80349485 100755 --- a/tests/src/test-python-greeter +++ b/tests/src/test-python-greeter @@ -107,7 +107,6 @@ def request_cb (channel, condition): r = '%s LOG-SESSIONS' % greeter_id if request == r: sessions = LightDM.get_sessions (); - sessions.sort (key = lambda x: x.get_key ()) for session in sessions: status_notify ('%s LOG-SESSION KEY=%s' % (greeter_id, session.get_key ())) diff --git a/tests/src/test-qt-greeter.cpp b/tests/src/test-qt-greeter.cpp index e95afa4f..558c1aac 100644 --- a/tests/src/test-qt-greeter.cpp +++ b/tests/src/test-qt-greeter.cpp @@ -194,7 +194,6 @@ request_cb (const gchar *name, GHashTable *params) QStringList names; for (int i = 0; i < sessions_model->rowCount (QModelIndex ()); i++) names.append (sessions_model->data (sessions_model->index (i, 0), QLightDM::SessionsModel::KeyRole).toString ()); - names.sort (); for (int i = 0; i < names.size (); i++) status_notify ("%s LOG-SESSION KEY=%s", greeter_id, qPrintable (names.at (i))); } diff --git a/tests/src/test-runner.c b/tests/src/test-runner.c index 1b961961..b1390c72 100644 --- a/tests/src/test-runner.c +++ b/tests/src/test-runner.c @@ -2487,6 +2487,7 @@ main (int argc, char **argv) g_mkdir_with_parents (g_strdup_printf ("%s/run", temp_dir), 0755); g_mkdir_with_parents (g_strdup_printf ("%s/usr/share", temp_dir), 0755); g_mkdir_with_parents (g_strdup_printf ("%s/usr/share/lightdm/sessions", temp_dir), 0755); + g_mkdir_with_parents (g_strdup_printf ("%s/usr/share/lightdm/other-sessions", temp_dir), 0755); g_mkdir_with_parents (g_strdup_printf ("%s/usr/share/lightdm/remote-sessions", temp_dir), 0755); g_mkdir_with_parents (g_strdup_printf ("%s/usr/share/lightdm/greeters", temp_dir), 0755); g_mkdir_with_parents (g_strdup_printf ("%s/tmp", temp_dir), 0755); @@ -2553,6 +2554,8 @@ main (int argc, char **argv) /* Copy over the greeter files */ if (system (g_strdup_printf ("cp %s/sessions/* %s/usr/share/lightdm/sessions", DATADIR, temp_dir))) perror ("Failed to copy sessions"); + if (system (g_strdup_printf ("cp %s/other-sessions/* %s/usr/share/lightdm/other-sessions", DATADIR, temp_dir))) + perror ("Failed to copy other sessions"); if (system (g_strdup_printf ("cp %s/remote-sessions/* %s/usr/share/lightdm/remote-sessions", DATADIR, temp_dir))) perror ("Failed to copy remote sessions"); if (system (g_strdup_printf ("cp %s/greeters/* %s/usr/share/lightdm/greeters", DATADIR, temp_dir))) diff --git a/tests/test-session-sort-01 b/tests/test-session-sort-01 new file mode 100755 index 00000000..e98d6bf0 --- /dev/null +++ b/tests/test-session-sort-01 @@ -0,0 +1,2 @@ +#!/bin/sh +./src/dbus-env ./src/test-runner session-sort-01 test-gobject-greeter diff --git a/tests/test-session-sort-02 b/tests/test-session-sort-02 new file mode 100755 index 00000000..b69ed713 --- /dev/null +++ b/tests/test-session-sort-02 @@ -0,0 +1,2 @@ +#!/bin/sh +./src/dbus-env ./src/test-runner session-sort-02 test-gobject-greeter