logind: rework GC logic
authorLennart Poettering <lennart@poettering.net>
Wed, 29 Nov 2023 10:24:10 +0000 (11:24 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 11 Jan 2024 16:23:48 +0000 (17:23 +0100)
commitd2a4c37972494aaf3deea5bc971bc45ab8f73f25
treef983f2e6532f45859df60a986d18c64a9614f983
parentb4f01bc1df625842c2db423b460a755c5817c1f9
logind: rework GC logic

In logind we generally want to stop user@.service for a user once they
log out. So the usual rule is that whenever a User object is around that
has no pinning sessions we should close it.

Except that it isn't that easy. We allow that user@.service is also
manually started, in which case the User object is created but not
pinned by any session.

Let's rework how this is handled: we define two different GC modes. In
one GC mode we'll keep the User object around whenever *any* session
exists (thus: including the user@.service session), and one where we
only keep it around whenever a *pinning* session exists (i.e. when a
user actually logs in, but the user@.service session doesn't count like
that).

And the trick is now that we start out in the *any* GC mode, and switch
to the *pinning* GC mode once the first user session logs in.

This should make things more robust as we know exactly in which state we
are and when to GC a user.
src/login/logind-dbus.c
src/login/logind-user.c
src/login/logind-user.h