mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
main: monitor SIGINT+SIGTERM using the FDM
This commit is contained in:
parent
cf1335f258
commit
89f49b5bc7
1 changed files with 10 additions and 9 deletions
19
main.c
19
main.c
|
|
@ -33,12 +33,11 @@
|
|||
#include "xmalloc.h"
|
||||
#include "xsnprintf.h"
|
||||
|
||||
static volatile sig_atomic_t aborted = 0;
|
||||
|
||||
static void
|
||||
sig_handler(int signo)
|
||||
static bool
|
||||
fdm_sigint(struct fdm *fdm, int signo, void *data)
|
||||
{
|
||||
aborted = 1;
|
||||
*(volatile sig_atomic_t *)data = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
|
@ -476,10 +475,10 @@ main(int argc, char *const *argv)
|
|||
if (as_server && (server = server_init(&conf, fdm, reaper, wayl)) == NULL)
|
||||
goto out;
|
||||
|
||||
/* Remember to restore signals in slave */
|
||||
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");
|
||||
volatile sig_atomic_t aborted = false;
|
||||
if (!fdm_signal_add(fdm, SIGINT, &fdm_sigint, (void *)&aborted) ||
|
||||
!fdm_signal_add(fdm, SIGTERM, &fdm_sigint, (void *)&aborted))
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
@ -512,6 +511,8 @@ out:
|
|||
render_destroy(renderer);
|
||||
wayl_destroy(wayl);
|
||||
reaper_destroy(reaper);
|
||||
fdm_signal_del(fdm, SIGTERM);
|
||||
fdm_signal_del(fdm, SIGINT);
|
||||
fdm_destroy(fdm);
|
||||
|
||||
config_free(conf);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue