mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
main: register signal handlers for SIGINT and SIGTERM
This commit is contained in:
parent
1e41a25f00
commit
32c6ed7069
1 changed files with 15 additions and 0 deletions
15
main.c
15
main.c
|
|
@ -5,6 +5,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <locale.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/sysinfo.h>
|
||||
|
|
@ -23,6 +24,14 @@
|
|||
#define min(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
|
||||
print_usage(const char *prog_name)
|
||||
{
|
||||
|
|
@ -164,6 +173,12 @@ main(int argc, char *const *argv)
|
|||
goto out;
|
||||
|
||||
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))
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue