From: Alan Jenkins Date: Wed, 28 Feb 2018 16:03:43 +0000 (+0000) Subject: core: don't freeze OnCalendar= timer units when the clock goes back a lot X-Git-Tag: v238~25^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=13f512d324e9e9be7286391347a185b716f0707c;p=thirdparty%2Fsystemd.git 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. --- 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); }