From 3027507e72efd1a9db0252fb819e3e2c0732cdeb Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 1 Dec 2018 23:20:06 +0000 Subject: [PATCH] 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. --- clunk.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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); -- 2.30.2