mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-10 05:33:51 -04: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 "xmalloc.h"
|
||||||
#include "xsnprintf.h"
|
#include "xsnprintf.h"
|
||||||
|
|
||||||
static volatile sig_atomic_t aborted = 0;
|
static bool
|
||||||
|
fdm_sigint(struct fdm *fdm, int signo, void *data)
|
||||||
static void
|
|
||||||
sig_handler(int signo)
|
|
||||||
{
|
{
|
||||||
aborted = 1;
|
*(volatile sig_atomic_t *)data = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
|
|
@ -476,10 +475,10 @@ main(int argc, char *const *argv)
|
||||||
if (as_server && (server = server_init(&conf, fdm, reaper, wayl)) == NULL)
|
if (as_server && (server = server_init(&conf, fdm, reaper, wayl)) == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* Remember to restore signals in slave */
|
volatile sig_atomic_t aborted = false;
|
||||||
const struct sigaction sa = {.sa_handler = &sig_handler};
|
if (!fdm_signal_add(fdm, SIGINT, &fdm_sigint, (void *)&aborted) ||
|
||||||
if (sigaction(SIGINT, &sa, NULL) < 0 || sigaction(SIGTERM, &sa, NULL) < 0) {
|
!fdm_signal_add(fdm, SIGTERM, &fdm_sigint, (void *)&aborted))
|
||||||
LOG_ERRNO("failed to register signal handlers");
|
{
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -512,6 +511,8 @@ out:
|
||||||
render_destroy(renderer);
|
render_destroy(renderer);
|
||||||
wayl_destroy(wayl);
|
wayl_destroy(wayl);
|
||||||
reaper_destroy(reaper);
|
reaper_destroy(reaper);
|
||||||
|
fdm_signal_del(fdm, SIGTERM);
|
||||||
|
fdm_signal_del(fdm, SIGINT);
|
||||||
fdm_destroy(fdm);
|
fdm_destroy(fdm);
|
||||||
|
|
||||||
config_free(conf);
|
config_free(conf);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue