[gdm/rhel-7.9: 24/51] daemon: run PostSession script from mnager not worker




commit 690f43762c28300ce17751c4423b2451f6a2b6f8
Author: Ray Strode <rstrode redhat com>
Date:   Thu Aug 29 09:34:04 2019 -0400

    daemon: run PostSession script from mnager not worker
    
    After a user logs out, the session worker baby sitting
    the session, may optionally run admin provided PostSession
    scripts.
    
    Those scripts aren't getting reliably run on reboots, because
    systemd kills the worker prematurely.
    
    There's no easy way to prevent this... the worker is part of
    the user session and user sessions are terminated immediately
    at shutdown time.
    
    This commit moves PostSession handling to the daemon process,
    where it can happen unimpeded by session bring down.
    
    This also makes the scripts more reliable in other potential
    cases where the worker is killed explicitly.

 daemon/gdm-manager.c        | 40 ++++++++++++++++++++++++++++++++++++++++
 daemon/gdm-session-worker.c |  3 ---
 2 files changed, 40 insertions(+), 3 deletions(-)
---
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
index 779b716be..d31c9d718 100644
--- a/daemon/gdm-manager.c
+++ b/daemon/gdm-manager.c
@@ -1960,6 +1960,41 @@ on_user_session_started (GdmSession      *session,
 #endif
 }
 
+static void
+run_post_session_script (GdmSession *session)
+{
+        GPid pid;
+        GdmDisplay *display;
+        gboolean display_is_local = FALSE;
+        const char *username;
+        g_autofree char *display_name = NULL, *remote_hostname = NULL, *display_auth_file = NULL;
+
+        display = get_display_for_user_session (session);
+
+        if (display == NULL)
+                return;
+
+        pid = gdm_session_get_pid (session);
+
+        if (pid <= 0)
+                return;
+
+        username = gdm_session_get_username (session);
+
+        g_object_get (G_OBJECT (display),
+                      "x11-display-name", &display_name,
+                      "is-local", &display_is_local,
+                      "remote-hostname", &remote_hostname,
+                      "x11-authority-file", &display_auth_file,
+                      NULL);
+
+        gdm_run_script (GDMCONFDIR "/PostSession",
+                        username,
+                        display_name,
+                        display_is_local? NULL : remote_hostname,
+                        display_auth_file);
+}
+
 static void
 remove_user_session (GdmManager *manager,
                      GdmSession *session)
@@ -1970,6 +2005,8 @@ remove_user_session (GdmManager *manager,
         display = get_display_for_user_session (session);
 
         if (display != NULL) {
+                run_post_session_script (session);
+
                 gdm_display_unmanage (display);
                 gdm_display_finish (display);
         }
@@ -2780,6 +2817,9 @@ gdm_manager_dispose (GObject *object)
                          (GDestroyNotify)
                          g_hash_table_unref);
 
+        g_list_foreach (manager->priv->user_sessions,
+                        (GFunc) run_post_session_script,
+                        NULL);
         g_list_foreach (manager->priv->user_sessions,
                         (GFunc) gdm_session_close,
                         NULL);
diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
index 07117d857..b0861b971 100644
--- a/daemon/gdm-session-worker.c
+++ b/daemon/gdm-session-worker.c
@@ -1770,18 +1770,15 @@ session_worker_child_watch (GPid              pid,
                  : WIFSIGNALED (status) ? WTERMSIG (status)
                  : -1);
 
-
         gdm_session_worker_uninitialize_pam (worker, PAM_SUCCESS);
 
         gdm_dbus_worker_emit_session_exited (GDM_DBUS_WORKER (worker),
                                              worker->priv->service,
                                              status);
-
         killpg (pid, SIGHUP);
 
         worker->priv->child_pid = -1;
         worker->priv->child_watch_id = 0;
-        run_script (worker, GDMCONFDIR "/PostSession");
 }
 
 static void


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