]> 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, 20 Dec 2024 19:43:57 +0000 (19:43 +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

(cherry picked from commit 718b31138b9a93f262259f297ad6b521454decc6)
(cherry picked from commit 9d36809256c6d92c6d8358769479ad2c2b695664)

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

index 71e4247a7991c7bbd8a96f6361aa3f9a383782f0..b12f43af67183a530b9a5bb5ba88aea25d3216ce 100644 (file)
@@ -404,10 +404,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, INHIBIT_BLOCK, t, false, false, 0, NULL);
 
         HASHMAP_FOREACH(s, m->sessions) {
index ac4b8602c4f9b11816595a8148d02278ff268e97..88e0e156b663c2da791b28cf45090385925b8a3b 100644 (file)
@@ -104,6 +104,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 cac6a3035731c05fc0e52a1832b4332b51c06686..9b1549d5da9e31801a0dd4d4be4f2f3a0cc52e3e 100644 (file)
@@ -141,6 +141,8 @@ struct Manager {
 
         char *efi_loader_entry_one_shot;
         struct stat efi_loader_entry_one_shot_stat;
+
+        dual_timestamp init_ts;
 };
 
 void manager_reset_config(Manager *m);