From 13f512d324e9e9be7286391347a185b716f0707c Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Wed, 28 Feb 2018 16:03:43 +0000 Subject: [PATCH] core: don't freeze OnCalendar= timer units when the clock goes back a lot E.g. if you have a monthly event and you set the computer clock back one year, we can allow the next 12 monthly events to happen naturally. In fact we already do this when you start a Persistent=yes timer, we just need to apply the same logic when it's running and we notice the system clock being set backwards. --- src/core/timer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/timer.c b/src/core/timer.c index e0f39584ced..ddb9c82b871 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -813,12 +813,21 @@ static void timer_reset_failed(Unit *u) { static void timer_time_change(Unit *u) { Timer *t = TIMER(u); + usec_t ts; assert(u); if (t->state != TIMER_WAITING) return; + /* If we appear to have triggered in the future, the system clock must + * have been set backwards. So let's rewind our own clock and allow + * the future trigger(s) to happen again :). Exactly the same as when + * you start a timer unit with Persistent=yes. */ + ts = now(CLOCK_REALTIME); + if (t->last_trigger.realtime > ts) + t->last_trigger.realtime = ts; + log_unit_debug(u, "Time change, recalculating next elapse."); timer_enter_waiting(t, false); } -- 2.39.2