]> git.netwichtig.de Git - user/henk/code/snooze.git/commitdiff
Reschedule when time moved backwards
authorChristian Neukirchen <chneukirchen@gmail.com>
Fri, 6 Nov 2015 21:45:18 +0000 (22:45 +0100)
committerChristian Neukirchen <chneukirchen@gmail.com>
Fri, 6 Nov 2015 21:46:51 +0000 (22:46 +0100)
README.md
snooze.c

index 4b6832c1ac397036415137ddd680a512abd3e0e2..29e0ca9127c6ecfc65c6e5ba5c1dd1464942e8ce 100644 (file)
--- a/README.md
+++ b/README.md
@@ -127,6 +127,7 @@ Only mtime is looked at, so touch(1) is good.
   execs the command.  You need to ensure (by setting up supervision)
   snooze runs again after that!
 * if we woke due to a SIGALRM, the command is executed immediately as well
+* if we notice time moved backwards, recompute the time until the event
 * if the event is in the future, recompute the time it takes, possibly
   considering shifting of the system time or timezone changes
   (timezone reload only tested on glibc)
index 60f7bffae8f813ee3e08929faeaca15a9201ee80..3a5185d7f13a30fbd7354e379de0fe6960f4cb0d 100644 (file)
--- a/snooze.c
+++ b/snooze.c
@@ -230,6 +230,7 @@ int main(int argc, char *argv[])
        int c;
        time_t t;
        time_t now = time(0);
+       time_t last = 0;
 
        /* default: every day at 00:00:00 */
        memset(weekday, '*', sizeof weekday);
@@ -348,6 +349,11 @@ int main(int argc, char *argv[])
 
        while (!alarm_rang) {
                now = time(0);
+               if (now < last) {
+                       t = find_next(now);
+                       if (vflag)
+                               printf("Time moved backwards, rescheduled for %s\n", isotime(tm));
+               }
                t = mktime(tm);
                if (t <= now) {
                        if (now - t <= slack)  // still about time
@@ -365,6 +371,7 @@ int main(int argc, char *argv[])
                        struct timespec ts;
                        ts.tv_nsec = 0;
                        ts.tv_sec = t - now > SLEEP_PHASE ? SLEEP_PHASE : t - now;
+                       last = now;
                        nanosleep(&ts, 0);
                        // we just iterate again when this exits early
                }