main: register signal handlers for SIGINT and SIGTERM

This commit is contained in:
Daniel Eklöf 2019-11-01 20:35:42 +01:00
parent 1e41a25f00
commit 32c6ed7069
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

15
main.c
View file

@ -5,6 +5,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <locale.h> #include <locale.h>
#include <getopt.h> #include <getopt.h>
#include <signal.h>
#include <errno.h> #include <errno.h>
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
@ -23,6 +24,14 @@
#define min(x, y) ((x) < (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y))
static volatile sig_atomic_t aborted = 0;
static void
sig_handler(int signo)
{
aborted = 1;
}
static void static void
print_usage(const char *prog_name) print_usage(const char *prog_name)
{ {
@ -164,6 +173,12 @@ main(int argc, char *const *argv)
goto out; goto out;
while (tll_length(wayl->terms) > 0) { while (tll_length(wayl->terms) > 0) {
const struct sigaction sa = {.sa_handler = &sig_handler};
if (sigaction(SIGINT, &sa, NULL) < 0 || sigaction(SIGTERM, &sa, NULL) < 0) {
LOG_ERRNO("failed to register signal handlers");
goto out;
}
if (!fdm_poll(fdm)) if (!fdm_poll(fdm))
break; break;