From 7cd0f0f844a0af629c85e4295904a4374bd076dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 14 Oct 2017 12:43:06 +0200 Subject: [PATCH 1/2] logind: allow two very close error messages to be distinguished In https://bugzilla.redhat.com/show_bug.cgi?id=1486859 error messages appera: Sep 06 19:09:07 ld92.e.math.uh.edu audit[21482]: AVC avc: denied { read } for pid=21482 comm="systemd-logind" name="dbus-1" dev="tmpfs" ino=5548194 scontext=system_u:system_r:systemd_logind_t:s0 tcontext=unconfined_u:object_r:session_dbusd_tmp_t:s0 tclass=dir permissive=0 Sep 06 19:09:07 ld92.e.math.uh.edu systemd-logind[21482]: Failed to remove runtime directory /run/user/8664: Permission denied But it's not clear which of the two rm_rf's is the source. Let's make them different. --- src/login/logind-user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/login/logind-user.c b/src/login/logind-user.c index dcf367e22d..d651a6f746 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -541,7 +541,7 @@ static int user_remove_runtime_path(User *u) { r = rm_rf(u->runtime_path, 0); if (r < 0) - log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path); + log_error_errno(r, "Failed to remove runtime directory %s (before unmounting): %m", u->runtime_path); /* Ignore cases where the directory isn't mounted, as that's * quite possible, if we lacked the permissions to mount @@ -552,7 +552,7 @@ static int user_remove_runtime_path(User *u) { r = rm_rf(u->runtime_path, REMOVE_ROOT); if (r < 0) - log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path); + log_error_errno(r, "Failed to remove runtime directory %s (after unmounting): %m", u->runtime_path); return r; } From 8cb83266062b383cdd4a57301ef559d64b491c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 14 Oct 2017 17:09:54 +0200 Subject: [PATCH 2/2] logind: fix killing of scopes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scope_abandon() called unit_watch_all_pids() to check if there are any pids in the cgroup, but unit_watch_all_pids() does nothing (and returns an empty set of pids) when cg_unified_controller(SYSTEMD) returns true. On hybrid or unified, cg_unified_controller(SYSTEMD) returns 1, so scope_abandon() thinks the scope is empty, even though it's not, and marks the scope dead prematurely. Example output after the scope is marked dead with processes still being present: ● session-24.scope - Session 24 of user guest Loaded: loaded (/run/systemd/transient/session-24.scope; transient; vendor preset: disabled) Transient: yes Active: inactive (dead) since Sat 2017-10-14 15:36:22 CEST; 5min ago Tasks: 1 CGroup: /user.slice/user-1001.slice/session-24.scope └─17309 sleep infinity Subsequent calls to stop the scope unit do nothing, because systemd thinks the scope is already dead. https://bugzilla.redhat.com/show_bug.cgi?id=1486859 This is easily reproducible on both F26 and F27: > ssh guest@localhost $ pulseaudio & sleep infinity & disown; exit $ systemctl status $$ > systemctl status session-NN.scope Tested with unified, hybrid, and legacy layouts, seems to work. --- src/core/scope.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/core/scope.c b/src/core/scope.c index 4cd5e3dd2a..7e789ed147 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -522,6 +522,7 @@ int scope_abandon(Scope *s) { s->was_abandoned = true; s->controller = mfree(s->controller); + scope_set_state(s, SCOPE_ABANDONED); /* The client is no longer watching the remaining processes, * so let's step in here, under the assumption that the @@ -531,12 +532,6 @@ int scope_abandon(Scope *s) { unit_tidy_watch_pids(UNIT(s), 0, 0); unit_watch_all_pids(UNIT(s)); - /* If the PID set is empty now, then let's finish this off */ - if (set_isempty(UNIT(s)->pids)) - scope_notify_cgroup_empty_event(UNIT(s)); - else - scope_set_state(s, SCOPE_ABANDONED); - return 0; }