/*** Main ***/
+static sigset_t term_sigs;
static volatile sig_atomic_t want_shutdown;
static void sigterm_handler(int sig __attribute__((unused)))
want_shutdown = 1;
}
+static void interruptible_sleep(int seconds)
+{
+ sigprocmask(SIG_UNBLOCK, &term_sigs, NULL);
+ sleep(seconds);
+ sigprocmask(SIG_BLOCK, &term_sigs, NULL);
+}
+
static const struct option long_options[] = {
{ "debug", 0, NULL, 'd' },
{ "log-dir", 1, NULL, 'l' },
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
- sigset_t term_sigs;
sigemptyset(&term_sigs);
sigaddset(&term_sigs, SIGTERM);
sigaddset(&term_sigs, SIGINT);
inited = 1;
log_error("Data logger not connected, waiting until it appears");
}
- sleep(30);
+ interruptible_sleep(30);
continue;
}
log_info("Listening");
want_sleep = 1;
if (err > 0 && parse_packet(reply))
want_sleep = 0;
- sigprocmask(SIG_UNBLOCK, &term_sigs, NULL);
if (want_sleep) {
- sleep(4);
+ interruptible_sleep(4);
want_stats = 1;
}
- sigprocmask(SIG_BLOCK, &term_sigs, NULL);
}
log_info("Disconnecting data logger");
release_device();
inited = 0;
- sleep(10);
+ interruptible_sleep(10);
}
log_info("Terminated");