chiark / gitweb /
Base the fallback timeout on how long we were expecting to sleep.
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 24 Nov 2018 10:21:09 +0000 (10:21 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 8 Dec 2018 22:30:09 +0000 (22:30 +0000)
That way, if we were planning to sleep for a second we won't wait 31 s
before discovering that the clock's been set back.

clunk.c

diff --git a/clunk.c b/clunk.c
index 4f9fd0b0dee13d933ec3092f2a81d78202ad659a..56f6b790363d2e2b9b186461a3028e5c46bfe0c8 100644 (file)
--- a/clunk.c
+++ b/clunk.c
@@ -276,7 +276,6 @@ run()
        const struct itimerspec its_disarm = {
                .it_value =  { .tv_sec = 0, .tv_nsec = 0 },
        };
-       struct timespec const timeout = { .tv_sec = 31, .tv_nsec = 0 };
        struct tm tm;
        int tick;
 
@@ -307,7 +306,8 @@ run()
                if (timer_settime(main_timer, TIMER_ABSTIME, &its_main, NULL)
                    != 0)
                        err(1, "timer_settime (arm main)");
-               if (sigtimedwait(&timing_signals, NULL, &timeout) == -1) {
+               if (sigtimedwait(&timing_signals, NULL, &TS_SEC(tick + 1))
+                   == -1) {
                        if (errno != EAGAIN)
                                err(1, "sigtimedwait");
                        /* Fallback timeout expired. */