]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind-dbus: set gc_mode to USER_GC_BY_PIN when disable linger
authorTom Yan <tom.ty89@gmail.com>
Mon, 8 Jul 2024 14:10:43 +0000 (22:10 +0800)
committerLennart Poettering <lennart@poettering.net>
Tue, 9 Jul 2024 11:53:10 +0000 (13:53 +0200)
The mode switch from any to pin is currently done in create_session().
However, if no (pinning) session is created before (or after) linger
is disabled, the user will not be gc'd after that. Therefore, also
perform the mode switch when linger is being disabled.

src/login/logind-dbus.c

index 3e419bb62e560fef6d5bffbd6292cbd797739abf..f6b37c64654ad4b39f149db8bcda57d109cb24f2 100644 (file)
@@ -1509,8 +1509,11 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu
                         return -errno;
 
                 u = hashmap_get(m->users, UID_TO_PTR(uid));
-                if (u)
+                if (u) {
+                        /* Make sure that disabling lingering will terminate the user tracking if no sessions pin it. */
+                        u->gc_mode = USER_GC_BY_PIN;
                         user_add_to_gc_queue(u);
+                }
         }
 
         return sd_bus_reply_method_return(message, NULL);