]> git.ipfire.org Git - thirdparty/systemd.git/commit
logind: keep lingering users at startup-time GC
authorRocker Zhang <zhang.rocker.liyuan@gmail.com>
Sat, 16 May 2026 05:07:56 +0000 (13:07 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 21 May 2026 07:53:07 +0000 (08:53 +0100)
commit9f25feb4ed18bb3d1e21de932279b2b1b3098846
tree1db3748fc7015f553154c4108754005cd9582bf7
parentebd70a53d4c7f66c415f505e3eec2f7fc0d67eea
logind: keep lingering users at startup-time GC

manager_startup() runs manager_gc(m, /* drop_not_started= */ false)
before the user_start() loop. user_may_gc()'s linger guard requires
user_unit_active() to be true to keep a user, but at this point the
per-user units have not been started yet, so for any lingering user
that ended up in the user_gc_queue the guard falls through and
manager_gc frees the User struct before user_start() ever runs.

This only manifests after `systemctl soft-reboot`, because /run is
tmpfs and survives soft-reboot: /run/systemd/users/UID files persist,
and manager_enumerate_users() in src/login/logind.c explicitly calls
user_add_to_gc_queue() for every UID it loads from there. Cold boot is
unaffected because /run is empty, so the linger users that come in via
manager_enumerate_linger_users() never enter the GC queue at all and
reach user_start() directly.

Special-case the startup-time GC: if a linger file exists, keep the
user regardless of unit state — user_start() is about to run and will
queue the appropriate jobs. Steady-state GC (drop_not_started=true, in
the event loop) still requires user_unit_active() so we don't hold on
to records for lingering users whose units genuinely died.

Fixes: https://github.com/systemd/systemd/issues/41789
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
src/login/logind-user.c