struct timespec ts;
struct sigevent sev;
struct sigaction sa;
+ char *statefile = NULL, *statestr = NULL;
int opt;
tzset();
while ((opt = getopt(argc, argv, "f:s:")) != -1) {
switch (opt) {
case 'f':
- init_statefile(optarg);
+ statefile = optarg;
break;
case 's':
- init_statestring(optarg);
+ statestr = optarg;
break;
}
}
+ if (statefile != NULL)
+ init_statefile(statefile);
+ /* Allow -s to override state read from file. */
+ if (statestr != NULL)
+ init_statestring(statestr);
}
enum need_adjust { STOP, TICK, ADVANCE };
run()
{
struct timespec ts;
- struct itimerspec its;
+ const struct itimerspec its = {
+ .it_value = { .tv_sec = 35, .tv_nsec = 0},
+ .it_interval = { .tv_sec = 1, .tv_nsec = 0},
+ };
+ const struct itimerspec its_disarm = {
+ .it_value = { .tv_sec = 0, .tv_nsec = 0 },
+ };
struct tm tm;
int tick;
/* Choose when next tick will be. */
ts.tv_nsec = 1000000000 - pulsewidth;
ts.tv_sec += tick - 1;
- its.it_value.tv_sec = 35;
- its.it_value.tv_nsec = 0;
- its.it_interval.tv_sec = 1;
- its.it_interval.tv_nsec = 0;
if (timer_settime(fallback_timer, 0, &its, NULL) != 0)
err(1, "timer_settime (arm)");
errno = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME,
&ts, NULL);
- its.it_value.tv_sec = 0;
if (errno != 0 && errno != EINTR)
err(1, "clock_nanosleep");
- if (timer_settime(fallback_timer, 0, &its, NULL) != 0)
+ if (timer_settime(fallback_timer, 0, &its_disarm, NULL) != 0)
err(1, "timer_settime (disarm)");
}
}