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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user