summaryrefslogtreecommitdiff
path: root/src/core/timer.c
diff options
context:
space:
mode:
authorTaro Yamada <archer_ame@yahoo.co.jp>2019-02-19 21:01:50 +0900
committerTaro Yamada <archer_ame@yahoo.co.jp>2019-02-21 20:33:21 +0900
commita87c1d3a979f8c2641471bed93577558a1027a24 (patch)
tree4ce63ddfc7a5682fb85aec5724e98de13a8ad6c1 /src/core/timer.c
parent8605a4b9eb1081a2f56745b57dc5d13a7637048e (diff)
downloadsystemd-a87c1d3a979f8c2641471bed93577558a1027a24.tar.gz
core: delay persistent timers by "RandomizedDelaySec=" at boot.
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.
Diffstat (limited to 'src/core/timer.c')
-rw-r--r--src/core/timer.c7
1 files changed, 7 insertions, 0 deletions
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