From 3a13442bbf72e7ebdd0b4d60c2922ea7c5cc9496 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 2 Aug 2018 20:56:34 +0200 Subject: [PATCH 1/4] user-runtime-dir: downgrade a few log messages to LOG_DEBUG that we ignore As the comments already say it might be quite likely that $XDG_RUNTIME_DIR is not set up as mount, and we shouldn't complain about that. Moreover, let's make this idempotent, so that a runtime dir that is already gone and is removed again doesn't cause failure. --- src/login/user-runtime-dir.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/login/user-runtime-dir.c b/src/login/user-runtime-dir.c index de4061c75e..51b864c9f8 100644 --- a/src/login/user-runtime-dir.c +++ b/src/login/user-runtime-dir.c @@ -95,20 +95,19 @@ static int user_remove_runtime_path(const char *runtime_path) { r = rm_rf(runtime_path, 0); if (r < 0) - log_error_errno(r, "Failed to remove runtime directory %s (before unmounting): %m", runtime_path); + log_debug_errno(r, "Failed to remove runtime directory %s (before unmounting), ignoring: %m", runtime_path); - /* Ignore cases where the directory isn't mounted, as that's - * quite possible, if we lacked the permissions to mount - * something */ + /* Ignore cases where the directory isn't mounted, as that's quite possible, if we lacked the permissions to + * mount something */ r = umount2(runtime_path, MNT_DETACH); if (r < 0 && !IN_SET(errno, EINVAL, ENOENT)) - log_error_errno(errno, "Failed to unmount user runtime directory %s: %m", runtime_path); + log_debug_errno(errno, "Failed to unmount user runtime directory %s, ignoring: %m", runtime_path); r = rm_rf(runtime_path, REMOVE_ROOT); - if (r < 0) - log_error_errno(r, "Failed to remove runtime directory %s (after unmounting): %m", runtime_path); + if (r < 0 && r != -ENOENT) + return log_error_errno(r, "Failed to remove runtime directory %s (after unmounting): %m", runtime_path); - return r; + return 0; } static int do_mount(const char *user) { From d06e8fbce35c2b52ee1d09af4888876d5f2d7ae4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 2 Aug 2018 20:57:56 +0200 Subject: [PATCH 2/4] units: make sure user-runtime-dir@.service is Type=oneshot We order user@.service after it, hence we need to properly know when it finished starting up. --- units/user-runtime-dir@.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/units/user-runtime-dir@.service.in b/units/user-runtime-dir@.service.in index 3a852b68a6..7bb41d75e5 100644 --- a/units/user-runtime-dir@.service.in +++ b/units/user-runtime-dir@.service.in @@ -15,4 +15,5 @@ StopWhenUnneeded=yes [Service] ExecStart=@rootlibexecdir@/systemd-user-runtime-dir start %i ExecStop=@rootlibexecdir@/systemd-user-runtime-dir stop %i +Type=oneshot RemainAfterExit=true From eb748aef4fbfd03b64938aa471bb8ceda1bc89a8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 3 Aug 2018 10:42:09 +0200 Subject: [PATCH 3/4] units: order user-runtime-dir@.service after systemd-user-sessions.service We use systemd-user-sessions.service as barrier when to allow login sessions. With this patch user@.service is ordered after that too, so that any login related code (which user-runtime-dir@.service is) is guaranteed to run after the barrier, and never before. --- units/user-runtime-dir@.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/units/user-runtime-dir@.service.in b/units/user-runtime-dir@.service.in index 7bb41d75e5..a187bb2839 100644 --- a/units/user-runtime-dir@.service.in +++ b/units/user-runtime-dir@.service.in @@ -10,6 +10,7 @@ [Unit] Description=/run/user/%i mount wrapper Documentation=man:user@.service(5) +After=systemd-user-sessions.service StopWhenUnneeded=yes [Service] From 1193c11a04b3ecc29925904fbeb5d64834bce73e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 3 Aug 2018 10:45:31 +0200 Subject: [PATCH 4/4] units: assign user-runtime-dir@.service to user-%i.slice This service won't use much resources, but it's certainly nicer to see it attached th the user's slice along with user@.service, so that everything we run for a specific user is properly bound into one unit. --- units/user-runtime-dir@.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/units/user-runtime-dir@.service.in b/units/user-runtime-dir@.service.in index a187bb2839..434413525e 100644 --- a/units/user-runtime-dir@.service.in +++ b/units/user-runtime-dir@.service.in @@ -18,3 +18,4 @@ ExecStart=@rootlibexecdir@/systemd-user-runtime-dir start %i ExecStop=@rootlibexecdir@/systemd-user-runtime-dir stop %i Type=oneshot RemainAfterExit=true +Slice=user-%i.slice