Blame SOURCES/0028-gdm-wayland-session-gdm-x-session-register-after-del.patch

a1b388
From 3073c23c673ede5093c1f93fb0775c2cd3203d7f Mon Sep 17 00:00:00 2001
a1b388
From: Ray Strode <rstrode@redhat.com>
a1b388
Date: Thu, 30 Aug 2018 16:09:02 -0400
a1b388
Subject: [PATCH 28/51] gdm-wayland-session,gdm-x-session: register after delay
a1b388
a1b388
Right now gdm-x-session registers with GDM as soon as the
a1b388
X server is started, and gdm-wayland-session registers as
a1b388
soon as the session is started.
a1b388
a1b388
Ideally registration wouldn't happen until the session
a1b388
says things started successfully.
a1b388
a1b388
This commit inches us toward that ideal but adding a little
a1b388
timeout before proceeding with registration.
a1b388
a1b388
A future commit will add a new xsession file key to allow
a1b388
us to know whether or not the session manager of the session
a1b388
supports doing registration.
a1b388
---
a1b388
 daemon/gdm-wayland-session.c | 23 ++++++++++++++++-------
a1b388
 daemon/gdm-x-session.c       | 25 +++++++++++++++++--------
a1b388
 2 files changed, 33 insertions(+), 15 deletions(-)
a1b388
a1b388
diff --git a/daemon/gdm-wayland-session.c b/daemon/gdm-wayland-session.c
a1b388
index 94f49e19c..de1991b34 100644
a1b388
--- a/daemon/gdm-wayland-session.c
a1b388
+++ b/daemon/gdm-wayland-session.c
a1b388
@@ -427,60 +427,75 @@ init_state (State **state)
a1b388
         static State state_allocation;
a1b388
 
a1b388
         *state = &state_allocation;
a1b388
 }
a1b388
 
a1b388
 static void
a1b388
 clear_state (State **out_state)
a1b388
 {
a1b388
         State *state = *out_state;
a1b388
 
a1b388
         g_clear_object (&state->cancellable);
a1b388
         g_clear_object (&state->bus_connection);
a1b388
         g_clear_object (&state->session_subprocess);
a1b388
         g_clear_pointer (&state->environment, g_strfreev);
a1b388
         g_clear_pointer (&state->main_loop, g_main_loop_unref);
a1b388
         *out_state = NULL;
a1b388
 }
a1b388
 
a1b388
 static gboolean
a1b388
 on_sigterm (State *state)
a1b388
 {
a1b388
         g_cancellable_cancel (state->cancellable);
a1b388
 
a1b388
         if (g_main_loop_is_running (state->main_loop)) {
a1b388
                 g_main_loop_quit (state->main_loop);
a1b388
         }
a1b388
 
a1b388
         return G_SOURCE_CONTINUE;
a1b388
 }
a1b388
 
a1b388
+static gboolean
a1b388
+on_registration_delay_complete (State *state)
a1b388
+{
a1b388
+        gboolean ret;
a1b388
+
a1b388
+        ret = register_display (state, state->cancellable);
a1b388
+
a1b388
+        if (!ret) {
a1b388
+                g_printerr ("Unable to register display with display manager\n");
a1b388
+                g_main_loop_quit (state->main_loop);
a1b388
+        }
a1b388
+
a1b388
+        return G_SOURCE_REMOVE;
a1b388
+}
a1b388
+
a1b388
 int
a1b388
 main (int    argc,
a1b388
       char **argv)
a1b388
 {
a1b388
         State           *state = NULL;
a1b388
         GOptionContext  *context = NULL;
a1b388
         static char    **args = NULL;
a1b388
         gboolean         debug = FALSE;
a1b388
         gboolean         ret;
a1b388
         int              exit_status = EX_OK;
a1b388
         static GOptionEntry entries []   = {
a1b388
                 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, "", "" },
a1b388
                 { NULL }
a1b388
         };
a1b388
 
a1b388
         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
a1b388
         textdomain (GETTEXT_PACKAGE);
a1b388
         setlocale (LC_ALL, "");
a1b388
 
a1b388
         gdm_log_init ();
a1b388
 
a1b388
         context = g_option_context_new (_("GNOME Display Manager Wayland Session Launcher"));
a1b388
         g_option_context_add_main_entries (context, entries, NULL);
a1b388
 
a1b388
         g_option_context_parse (context, &argc, &argv, NULL);
a1b388
         g_option_context_free (context);
a1b388
 
a1b388
         if (args == NULL || args[0] == NULL || args[1] != NULL) {
a1b388
                 g_warning ("gdm-wayland-session takes one argument (the session)");
a1b388
                 exit_status = EX_USAGE;
a1b388
@@ -501,55 +516,49 @@ main (int    argc,
a1b388
         }
a1b388
 
a1b388
         gdm_settings_direct_get_boolean (GDM_KEY_DEBUG, &debug);
a1b388
         state->debug_enabled = debug;
a1b388
 
a1b388
         gdm_log_set_debug (debug);
a1b388
 
a1b388
         state->main_loop = g_main_loop_new (NULL, FALSE);
a1b388
         state->cancellable = g_cancellable_new ();
a1b388
 
a1b388
         g_unix_signal_add (SIGTERM, (GSourceFunc) on_sigterm, state);
a1b388
 
a1b388
         ret = spawn_bus (state, state->cancellable);
a1b388
 
a1b388
         if (!ret) {
a1b388
                 g_printerr ("Unable to run session message bus\n");
a1b388
                 exit_status = EX_SOFTWARE;
a1b388
                 goto out;
a1b388
         }
a1b388
 
a1b388
         import_environment (state, state->cancellable);
a1b388
 
a1b388
         ret = spawn_session (state, state->cancellable);
a1b388
 
a1b388
         if (!ret) {
a1b388
                 g_printerr ("Unable to run session\n");
a1b388
                 exit_status = EX_SOFTWARE;
a1b388
                 goto out;
a1b388
         }
a1b388
 
a1b388
-        ret = register_display (state, state->cancellable);
a1b388
-
a1b388
-        if (!ret) {
a1b388
-                g_printerr ("Unable to register display with display manager\n");
a1b388
-                exit_status = EX_SOFTWARE;
a1b388
-                goto out;
a1b388
-        }
a1b388
+        g_timeout_add_seconds (2, (GSourceFunc) on_registration_delay_complete, state);
a1b388
 
a1b388
         g_main_loop_run (state->main_loop);
a1b388
 
a1b388
         /* Only use exit status of session if we're here because it exit */
a1b388
 
a1b388
         if (state->session_subprocess == NULL) {
a1b388
                 exit_status = state->session_exit_status;
a1b388
         }
a1b388
 
a1b388
 out:
a1b388
         if (state != NULL) {
a1b388
                 signal_subprocesses (state);
a1b388
                 wait_on_subprocesses (state);
a1b388
                 clear_state (&state);
a1b388
         }
a1b388
 
a1b388
         return exit_status;
a1b388
 }
a1b388
diff --git a/daemon/gdm-x-session.c b/daemon/gdm-x-session.c
a1b388
index 3b2fcef47..412999cf5 100644
a1b388
--- a/daemon/gdm-x-session.c
a1b388
+++ b/daemon/gdm-x-session.c
a1b388
@@ -783,60 +783,75 @@ init_state (State **state)
a1b388
 }
a1b388
 
a1b388
 static void
a1b388
 clear_state (State **out_state)
a1b388
 {
a1b388
         State *state = *out_state;
a1b388
 
a1b388
         g_clear_object (&state->cancellable);
a1b388
         g_clear_object (&state->bus_connection);
a1b388
         g_clear_object (&state->session_subprocess);
a1b388
         g_clear_object (&state->x_subprocess);
a1b388
         g_clear_pointer (&state->environment, g_strfreev);
a1b388
         g_clear_pointer (&state->auth_file, g_free);
a1b388
         g_clear_pointer (&state->display_name, g_free);
a1b388
         g_clear_pointer (&state->main_loop, g_main_loop_unref);
a1b388
         *out_state = NULL;
a1b388
 }
a1b388
 
a1b388
 static gboolean
a1b388
 on_sigterm (State *state)
a1b388
 {
a1b388
         g_cancellable_cancel (state->cancellable);
a1b388
 
a1b388
         if (g_main_loop_is_running (state->main_loop)) {
a1b388
                 g_main_loop_quit (state->main_loop);
a1b388
         }
a1b388
 
a1b388
         return G_SOURCE_CONTINUE;
a1b388
 }
a1b388
 
a1b388
+static gboolean
a1b388
+on_registration_delay_complete (State *state)
a1b388
+{
a1b388
+        gboolean ret;
a1b388
+
a1b388
+        ret = register_display (state, state->cancellable);
a1b388
+
a1b388
+        if (!ret) {
a1b388
+                g_printerr ("Unable to register display with display manager\n");
a1b388
+                g_main_loop_quit (state->main_loop);
a1b388
+        }
a1b388
+
a1b388
+        return G_SOURCE_REMOVE;
a1b388
+}
a1b388
+
a1b388
 int
a1b388
 main (int    argc,
a1b388
       char **argv)
a1b388
 {
a1b388
         State           *state = NULL;
a1b388
         GOptionContext  *context = NULL;
a1b388
         static char    **args = NULL;
a1b388
         static gboolean  run_script = FALSE;
a1b388
         static gboolean  allow_remote_connections = FALSE;
a1b388
         gboolean         debug = FALSE;
a1b388
         gboolean         ret;
a1b388
         int              exit_status = EX_OK;
a1b388
         static GOptionEntry entries []   = {
a1b388
                 { "run-script", 'r', 0, G_OPTION_ARG_NONE, &run_script, N_("Run program through /etc/gdm/Xsession wrapper script"), NULL },
a1b388
                 { "allow-remote-connections", 'a', 0, G_OPTION_ARG_NONE, &allow_remote_connections, N_("Listen on TCP socket"), NULL },
a1b388
                 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, "", "" },
a1b388
                 { NULL }
a1b388
         };
a1b388
 
a1b388
         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
a1b388
         textdomain (GETTEXT_PACKAGE);
a1b388
         setlocale (LC_ALL, "");
a1b388
 
a1b388
         gdm_log_init ();
a1b388
 
a1b388
         context = g_option_context_new (_("GNOME Display Manager X Session Launcher"));
a1b388
         g_option_context_add_main_entries (context, entries, NULL);
a1b388
 
a1b388
         g_option_context_parse (context, &argc, &argv, NULL);
a1b388
         g_option_context_free (context);
a1b388
@@ -869,63 +884,57 @@ main (int    argc,
a1b388
         state->cancellable = g_cancellable_new ();
a1b388
 
a1b388
         g_unix_signal_add (SIGTERM, (GSourceFunc) on_sigterm, state);
a1b388
 
a1b388
         ret = spawn_x_server (state, allow_remote_connections, state->cancellable);
a1b388
 
a1b388
         if (!ret) {
a1b388
                 g_printerr ("Unable to run X server\n");
a1b388
                 exit_status = EX_SOFTWARE;
a1b388
                 goto out;
a1b388
         }
a1b388
 
a1b388
         ret = spawn_bus (state, state->cancellable);
a1b388
 
a1b388
         if (!ret) {
a1b388
                 g_printerr ("Unable to run session message bus\n");
a1b388
                 exit_status = EX_SOFTWARE;
a1b388
                 goto out;
a1b388
         }
a1b388
 
a1b388
         import_environment (state, state->cancellable);
a1b388
 
a1b388
         ret = update_bus_environment (state, state->cancellable);
a1b388
 
a1b388
         if (!ret) {
a1b388
                 g_printerr ("Unable to update bus environment\n");
a1b388
                 exit_status = EX_SOFTWARE;
a1b388
                 goto out;
a1b388
         }
a1b388
 
a1b388
-        ret = register_display (state, state->cancellable);
a1b388
-
a1b388
-        if (!ret) {
a1b388
-                g_printerr ("Unable to register display with display manager\n");
a1b388
-                exit_status = EX_SOFTWARE;
a1b388
-                goto out;
a1b388
-        }
a1b388
-
a1b388
         ret = spawn_session (state, run_script, state->cancellable);
a1b388
 
a1b388
         if (!ret) {
a1b388
                 g_printerr ("Unable to run session\n");
a1b388
                 exit_status = EX_SOFTWARE;
a1b388
                 goto out;
a1b388
         }
a1b388
 
a1b388
+        g_timeout_add_seconds (2, (GSourceFunc) on_registration_delay_complete, state);
a1b388
+
a1b388
         g_main_loop_run (state->main_loop);
a1b388
 
a1b388
         /* Only use exit status of session if we're here because it exit */
a1b388
 
a1b388
         if (state->session_subprocess == NULL) {
a1b388
                 exit_status = state->session_exit_status;
a1b388
         }
a1b388
 
a1b388
 out:
a1b388
         if (state != NULL) {
a1b388
                 signal_subprocesses (state);
a1b388
                 wait_on_subprocesses (state);
a1b388
                 clear_state (&state);
a1b388
         }
a1b388
 
a1b388
         return exit_status;
a1b388
 }
a1b388
-- 
a1b388
2.27.0
a1b388