From: Ben Harris Date: Sat, 24 Nov 2018 10:21:09 +0000 (+0000) Subject: Base the fallback timeout on how long we were expecting to sleep. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=f44b7ad28e0e416f3e16a8eb83c46edd7c959068;p=clunk.git Base the fallback timeout on how long we were expecting to sleep. 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. --- diff --git a/clunk.c b/clunk.c index 4f9fd0b..56f6b79 100644 --- 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. */