aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-01 19:35:42 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-01 19:36:55 +0000
commit32c6ed70699e341256428ffafd214aab1a6f52a2 (patch)
tree642acd3b9ef9ee0855e603def7b66f6d2eca4d5d
parentterminal: call user-defined callback when destroying terminal (diff)
main: register signal handlers for SIGINT and SIGTERM
-rw-r--r--main.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/main.c b/main.c
index 606b0199..fa69459b 100644
--- a/main.c
+++ b/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;