]> git.ipfire.org Git - thirdparty/systemd.git/commit
logind-user: track user started/stopping state through user-runtime-dir@.service
authorMike Yuan <me@yhndnzj.com>
Sat, 13 Jan 2024 18:38:11 +0000 (02:38 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 15 Feb 2024 11:23:44 +0000 (19:23 +0800)
commite2a42c0c43f6cdd7cb2b89521392248056eeac49
treec762abdb6a2f3df1fc1f8fcc646d5703f4233403
parent5518b72ba8e4e3e367f384387e8e22c4ecf1e02c
logind-user: track user started/stopping state through user-runtime-dir@.service

Before #30884, the user state is tied to user@.service (user service
manager). However, #30884 introduced sessions that need no manager,
and we can no longer rely on that.

Consider the following situation:

1. A 'background-light' session '1' is created (i.e. no user service manager
   is needed)
2. Session '1' scope unit pulls in user-runtime-dir@.service
3. Session '1' exits. A stop job is enqueued for user-runtime-dir@.service
   due to StopWhenUnneeded=yes
4. At the same time, another session '2' which requires user manager is started.
   However, session scope units have JobMode=fail, therefore the start job
   for user-runtime-dir@.service that was pulled in by session '2' scope job
   is deleted as it conflicts with the stop job.

We want session scope units to continue using JobMode=fail, but we still need
the dependencies to be started correctly, i.e. explicitly requested by logind
beforehand. Therefore, let's stop using StopWhenUnneeded=yes for
user-runtime-dir@.service, and track users' `started` and `stopping` state
based on that when user@.service is not needed. Then, for every invocation
of user_start(), we'll recheck if we need the service manager and start it
if so.

Also, the dependency type on user-runtime-dir@.service from user@.service
is upgraded to `BindsTo=`, in order to ensure that when logind stops the
former, the latter is stopped as well.
src/login/logind-dbus.c
src/login/logind-session-dbus.c
src/login/logind-session.c
src/login/logind-user-dbus.c
src/login/logind-user.c
src/login/logind-user.h
units/user-runtime-dir@.service.in
units/user@.service.in