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

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