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

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