From 5f41d1f10fd97e93517b6a762b1bec247f4d1171 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 6 Feb 2014 18:32:14 +0100 Subject: logind: rework session shutdown logic Simplify the shutdown logic a bit: - Keep the session FIFO around in the PAM module, even after the session shutdown hook has been finished. This allows logind to track precisely when the PAM handler goes away. - In the ReleaseSession() call start a timer, that will stop terminate the session when elapsed. - Never fiddle with the KillMode of scopes to configure whether user processes should be killed or not. Instead, simply leave the scope units around when we terminate a session whose processes should not be killed. - When killing is enabled, stop the session scope on FIFO EOF or after the ReleaseSession() timeout. When killing is disabled, simply tell PID 1 to abandon the scope. Because the scopes stay around and hence all processes are always member of a scope, the system shutdown logic should be more robust, as the scopes can be shutdown as part of the usual shutdown logic. --- src/login/logind.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/login/logind.c') diff --git a/src/login/logind.c b/src/login/logind.c index 48da7b173b..a6f84e8536 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -871,8 +871,15 @@ void manager_gc(Manager *m, bool drop_not_started) { LIST_REMOVE(gc_queue, m->session_gc_queue, session); session->in_gc_queue = false; - if (!session_check_gc(session, drop_not_started)) { + /* First, if we are not closing yet, initiate stopping */ + if (!session_check_gc(session, drop_not_started) && + session_get_state(session) != SESSION_CLOSING) session_stop(session); + + /* Normally, this should make the session busy again, + * if it doesn't then let's get rid of it + * immediately */ + if (!session_check_gc(session, drop_not_started)) { session_finalize(session); session_free(session); } @@ -882,8 +889,11 @@ void manager_gc(Manager *m, bool drop_not_started) { LIST_REMOVE(gc_queue, m->user_gc_queue, user); user->in_gc_queue = false; - if (!user_check_gc(user, drop_not_started)) { + if (!user_check_gc(user, drop_not_started) && + user_get_state(user) != USER_CLOSING) user_stop(user); + + if (!user_check_gc(user, drop_not_started)) { user_finalize(user); user_free(user); } -- cgit v1.2.3-54-g00ecf