Skip to content

Commit 11519da

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) (cherry picked from commit dcb86ed) (cherry picked from commit 331f36c)
1 parent 9c5789c commit 11519da

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

406406
assert(m);
407407

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

410414
HASHMAP_FOREACH(s, m->sessions) {

src/login/logind.c

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

8888
(void) sd_event_set_watchdog(m->event, true);
8989

90+
dual_timestamp_get(&m->init_ts);
91+
9092
manager_reset_config(m);
9193

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