logind: always abandon session scopes before killing them

This way systemd is informed that we consider everything inside the scope as
"left-over", and systemd can log about killing it.

With this change systemd will log about all processes killed due to the session
clean-up on KillUserProcesses=yes.
This commit is contained in:
Lennart Poettering 2016-07-20 13:42:36 +02:00
parent 3862e809d0
commit 756ed0e238

View file

@ -610,6 +610,14 @@ static int session_stop_scope(Session *s, bool force) {
if (!s->scope)
return 0;
/* Let's always abandon the scope first. This tells systemd that we are not interested anymore, and everything
* that is left in in the scope is "left-over". Informing systemd about this has the benefit that it will log
* when killing any processes left after this point. */
r = manager_abandon_scope(s->manager, s->scope, &error);
if (r < 0)
log_warning_errno(r, "Failed to abandon session scope, ignoring: %s", bus_error_message(&error, r));
/* Optionally, let's kill everything that's left now. */
if (force || manager_shall_kill(s->manager, s->user->name)) {
char *job = NULL;
@ -619,11 +627,8 @@ static int session_stop_scope(Session *s, bool force) {
free(s->scope_job);
s->scope_job = job;
} else {
r = manager_abandon_scope(s->manager, s->scope, &error);
if (r < 0)
return log_error_errno(r, "Failed to abandon session scope: %s", bus_error_message(&error, r));
}
} else
s->scope_job = mfree(s->scope_job);
return 0;
}