diff --git a/src/login/logind-core.c b/src/login/logind-core.c index af86e92c01..fe95f90f74 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -395,10 +395,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) { diff --git a/src/login/logind.c b/src/login/logind.c index f30f7f9370..75474e2c08 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -96,6 +96,8 @@ static int manager_new(Manager **ret) { (void) sd_event_set_watchdog(m->event, true); + dual_timestamp_get(&m->init_ts); + manager_reset_config(m); *ret = TAKE_PTR(m); diff --git a/src/login/logind.h b/src/login/logind.h index e6a04e0834..787406adac 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -139,6 +139,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);