chiark / gitweb /
Switch back to calling clock_gettime unconditionally at start-up.
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 1 Dec 2018 23:20:06 +0000 (23:20 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 8 Dec 2018 22:30:09 +0000 (22:30 +0000)
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

diff --git a/clunk.c b/clunk.c
index 0031e09b12a4ddaff0e8b3252eb06dae038aa1f2..1616dbd8e2a099ec41f150c15d2f36c020d9afe3 100644 (file)
--- 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);