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-user.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/login/logind-user.c') diff --git a/src/login/logind-user.c b/src/login/logind-user.c index bdb6915630..fdbf6e3aa0 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -515,6 +515,8 @@ int user_stop(User *u) { if (k < 0) r = k; + u->stopping = true; + user_save(u); return r; @@ -633,22 +635,27 @@ void user_add_to_gc_queue(User *u) { UserState user_get_state(User *u) { Session *i; - bool all_closing = true; assert(u); + if (u->stopping) + return USER_CLOSING; + if (u->slice_job || u->service_job) return USER_OPENING; - LIST_FOREACH(sessions_by_user, i, u->sessions) { - if (session_is_active(i)) - return USER_ACTIVE; - if (session_get_state(i) != SESSION_CLOSING) - all_closing = false; - } + if (u->sessions) { + bool all_closing = true; + + LIST_FOREACH(sessions_by_user, i, u->sessions) { + if (session_is_active(i)) + return USER_ACTIVE; + if (session_get_state(i) != SESSION_CLOSING) + all_closing = false; + } - if (u->sessions) return all_closing ? USER_CLOSING : USER_ONLINE; + } if (user_check_linger_file(u) > 0) return USER_LINGERING; -- cgit v1.2.3-54-g00ecf