Fixes #5659.
Currently, if Persistent=true and the machine is off at the scheduled time of the timer unit, the timer
will be triggered immediately at the next boot even if RandomizedDelaySec= is specified.
As a result, if multiple timers meet that condition, they will be triggered at the same time and too
much CPU/IO work makes boot slow down.
With this commit, if the scheduled time of the persistent timer has already elapsed at boot,
set the time when systemd first started as the scheduled time and RandomizedDelaySec= is applied to it.
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