Skip to content

Commit cd6f07e

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)
1 parent 543784e commit cd6f07e

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
@@ -399,10 +399,14 @@ int manager_get_user_by_pid(Manager *m, pid_t pid, User **ret) {
399399
int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
400400
Session *s;
401401
bool idle_hint;
402-
dual_timestamp ts = DUAL_TIMESTAMP_NULL;
402+
dual_timestamp ts;
403403

404404
assert(m);
405405

406+
/* Initialize the baseline timestamp with the time the manager got initialized to avoid reporting
407+
* unreasonable large idle periods starting with the Unix epoch. */
408+
ts = m->init_ts;
409+
406410
idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, INHIBIT_BLOCK, t, false, false, 0, NULL);
407411

408412
HASHMAP_FOREACH(s, m->sessions) {

src/login/logind.c

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

103103
(void) sd_event_set_watchdog(m->event, true);
104104

105+
dual_timestamp_now(&m->init_ts);
106+
105107
manager_reset_config(m);
106108

107109
*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)