From: Alan Jenkins Date: Fri, 1 Jun 2018 18:03:21 +0000 (+0100) Subject: login: log session state "closing" (as well as New/Removed) X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a35a95b092b411179028c94fee69139a4afeedfd;p=elogind.git login: log session state "closing" (as well as New/Removed) Let's show a message at the time of logout i.e. entering the "closing" state, not just e.g. once the user closes `tmux` and the session can be removed completely. (At least when KillUserProcesses=no applies. My thinking was we can spare the log noise if we're killing the processes anyway). These are two independent events. I think the logout event is quite significant in the session lifecycle. It will be easier for a user who does not know logind details to understand why "Removed session" doesn't appear at logout time, if we have a specific message we can show at this time :). Tested using tmux and KillUserProcesses=no. I can also confirm the extra message doesn't show when using KillUserProcesses=yes. Maybe it looks a bit mysterious when you use KillOnlyUsers= / KillExcludeUsers=, but hopefully not alarmingly so. I was looking at systemd-logind messages on my system, because I can reproduce two separate problems with Gnome on Fedora 28 where sessions are unexpectedly in state "closing". (One where a GUI session limps along in a degraded state[1], and another where spice-vdagent is left alive after logout, keeping the session around[2]). It logged when sessions were created and removed, but it didn't log when the session entered the "closing" state. [1] https://bugzilla.redhat.com/show_bug.cgi?id=1583240#c1 [2] https://bugzilla.redhat.com/show_bug.cgi?id=1583261 Closes #9096 --- diff --git a/src/login/logind-session.c b/src/login/logind-session.c index e5adbdcf7..221fa9fb7 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -706,9 +706,20 @@ static int session_stop_scope(Session *s, bool force) { free(s->scope_job); s->scope_job = job; - } else + } else { s->scope_job = mfree(s->scope_job); + /* With no killing, this session is allowed to persist in "closing" state indefinitely. + * Therefore session stop and session removal may be two distinct events. + * Session stop is quite significant on its own, let's log it. */ + log_struct(s->class == SESSION_BACKGROUND ? LOG_DEBUG : LOG_INFO, + "SESSION_ID=%s", s->id, + "USER_ID=%s", s->user->name, + "LEADER="PID_FMT, s->leader, + LOG_MESSAGE("Session %s logged out. Waiting for processes to exit.", s->id), + NULL); + } + return 0; } #else