]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: let system-wide idle begin at the time logind was initialized
authorFlorian Schmaus <flo@geekplace.eu>
Sat, 16 Nov 2024 09:29:35 +0000 (10:29 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 13 Dec 2024 12:12:21 +0000 (12:12 +0000)
Initialize the start of the system-wide idle time with the time logind was
initialized and not with the start of the Unix epoch. This means that systemd
will not repport a unreasonable long idle time (around 54 years at the time of
writing this), especially at in the early boot, while no login manager session,
e.g,. gdm, had a chance to provide a more accurate start of the idle period.

Fixes #35163

src/login/logind-core.c
src/login/logind.c
src/login/logind.h

index bcb82582e64e5e7e4eb166f31e0fe702963cd0f5..a1c0069f6914b53e73f9da1affe4d7baa02f000b 100644 (file)
@@ -407,10 +407,14 @@ int manager_get_user_by_pid(Manager *m, pid_t pid, User **ret) {
 int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
         Session *s;
         bool idle_hint;
-        dual_timestamp ts = DUAL_TIMESTAMP_NULL;
+        dual_timestamp ts;
 
         assert(m);
 
+        /* Initialize the baseline timestamp with the time the manager got initialized to avoid reporting
+         * unreasonable large idle periods starting with the Unix epoch. */
+        ts = m->init_ts;
+
         idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, t, /* flags= */ 0, UID_INVALID, NULL);
 
         HASHMAP_FOREACH(s, m->sessions) {
index f88a2004fda5f1afe628ea8fe5ac9d4c1717d1af..8dc1781edffc9053fb1f38f4fffbd5e13670c527 100644 (file)
@@ -100,6 +100,8 @@ static int manager_new(Manager **ret) {
 
         (void) sd_event_set_watchdog(m->event, true);
 
+        dual_timestamp_now(&m->init_ts);
+
         manager_reset_config(m);
 
         *ret = TAKE_PTR(m);
index 1e17b610bc8c121004c64a62610654710636b5be..ce7e76e761b5e309965f33ec441b7770214c3eb6 100644 (file)
@@ -145,6 +145,8 @@ struct Manager {
         struct stat efi_loader_entry_one_shot_stat;
 
         CalendarSpec *maintenance_time;
+
+        dual_timestamp init_ts;
 };
 
 void manager_reset_config(Manager *m);