From: Ben Harris Date: Sat, 1 Dec 2018 23:20:06 +0000 (+0000) Subject: Switch back to calling clock_gettime unconditionally at start-up. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=3027507e72efd1a9db0252fb819e3e2c0732cdeb;p=clunk.git Switch back to calling clock_gettime unconditionally at start-up. This is necessary in the case where the state file is empty and "-s" is not used, and putting in the necessary conditions was getting too complicated. --- diff --git a/clunk.c b/clunk.c index 0031e09..1616dbd 100644 --- a/clunk.c +++ b/clunk.c @@ -304,18 +304,17 @@ init(int argc, char **argv) break; } } + /* Default startup state is to assume the dial is correct. */ + if (clock_gettime(CLOCK_REALTIME, &ts) != 0) + err(1, "clock_gettime"); + if (localtime_r(&ts.tv_sec, &displayed) == NULL) + err(1, "localtime_r"); + displayed.tm_sec = (displayed.tm_sec >= 30) ? 30 : 0; if (statefile != NULL) init_statefile(statefile); /* Allow -s to override state read from file. */ if (statestr != NULL) init_statestring(statestr); - if (statefile == NULL && statestr == NULL) { - if (clock_gettime(CLOCK_REALTIME, &ts) != 0) - err(1, "clock_gettime"); - if (localtime_r(&ts.tv_sec, &displayed) == NULL) - err(1, "localtime_r"); - displayed.tm_sec = (displayed.tm_sec >= 30) ? 30 : 0; - } #ifdef WITH_LIBGPIOD if (gpiod_line_name != NULL || gpiod_chip != NULL) init_libgpiod(gpiod_chip, gpiod_line_name, gpiod_line_num);