Skip to content

Commit dcb86ed

Browse files
Flowdalicbluca
authored andcommitted
logind: let system-wide idle begin at the time logind was initialized
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 718b311) (cherry picked from commit 9d36809) (cherry picked from commit 77b963c) (cherry picked from commit cd6f07e)
1 parent 27bb6c8 commit dcb86ed

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/login/logind-core.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,14 @@ int manager_get_user_by_pid(Manager *m, pid_t pid, User **ret) {
395395
int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
396396
Session *s;
397397
bool idle_hint;
398-
dual_timestamp ts = DUAL_TIMESTAMP_NULL;
398+
dual_timestamp ts;
399399

400400
assert(m);
401401

402+
/* Initialize the baseline timestamp with the time the manager got initialized to avoid reporting
403+
* unreasonable large idle periods starting with the Unix epoch. */
404+
ts = m->init_ts;
405+
402406
idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, INHIBIT_BLOCK, t, false, false, 0, NULL);
403407

404408
HASHMAP_FOREACH(s, m->sessions) {

src/login/logind.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ static int manager_new(Manager **ret) {
9696

9797
(void) sd_event_set_watchdog(m->event, true);
9898

99+
dual_timestamp_get(&m->init_ts);
100+
99101
manager_reset_config(m);
100102

101103
*ret = TAKE_PTR(m);

src/login/logind.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ struct Manager {
139139

140140
char *efi_loader_entry_one_shot;
141141
struct stat efi_loader_entry_one_shot_stat;
142+
143+
dual_timestamp init_ts;
142144
};
143145

144146
void manager_reset_config(Manager *m);

0 commit comments

Comments
 (0)