]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: don't freeze OnCalendar= timer units when the clock goes back a lot 8237/head
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Wed, 28 Feb 2018 16:03:43 +0000 (16:03 +0000)
committerAlan Jenkins <alan.christopher.jenkins@gmail.com>
Wed, 28 Feb 2018 17:00:07 +0000 (17:00 +0000)
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

index e0f39584ced407f5543df353a1e8399fbf6b621a..ddb9c82b8715e5edf4d38fd94d3a9c93bc538589 100644 (file)
@@ -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);
 }