diff --git a/src/core/timer.c b/src/core/timer.c index d9ba2f76b3..0c1ca3ef23 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -380,6 +380,13 @@ static void timer_enter_waiting(Timer *t, bool time_change) { if (r < 0) continue; + /* To make the delay due to RandomizedDelaySec= work even at boot, + * if the scheduled time has already passed, set the time when systemd + * first started as the scheduled time. + * Also, we don't have to check t->persistent since the logic implicitly express true. */ + if (v->next_elapse < UNIT(t)->manager->timestamps[MANAGER_TIMESTAMP_USERSPACE].realtime) + v->next_elapse = UNIT(t)->manager->timestamps[MANAGER_TIMESTAMP_USERSPACE].realtime; + if (!found_realtime) t->next_elapse_realtime = v->next_elapse; else