From 9cc0a7f4ab4b0584bf06a4713563d96e4a3a9a72 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 29 Sep 2019 23:49:17 +0200 Subject: catch SIGSEGV as well; register sa_handlers only if its SIG_DLF before --- src/sig_handlers.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/sig_handlers.c (limited to 'src/sig_handlers.c') diff --git a/src/sig_handlers.c b/src/sig_handlers.c new file mode 100644 index 0000000..601e454 --- /dev/null +++ b/src/sig_handlers.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +static void abnormal_termination_handler(int signo) { + exit(signo); +} + +static void __attribute__((constructor)) register_handlers(void) +{ + struct sigaction sa, old_sa; + sa.sa_handler = abnormal_termination_handler; + sigemptyset(&sa.sa_mask); + + sigaction(SIGABRT, NULL, &old_sa); + if (old_sa.sa_handler == SIG_DFL) { + if (sigaction(SIGABRT, &sa, NULL) == -1) { + perror("sigaction"); + exit(1); + } + } else { + fprintf(stderr, "SIGABRT handler already set"); + } + + sigaction(SIGSEGV, NULL, &old_sa); + if (old_sa.sa_handler == SIG_DFL) { + if (sigaction(SIGSEGV, &sa, NULL) == -1) { + perror("sigaction"); + exit(1); + } + } else { + fprintf(stderr, "SIGSEGV handler already set"); + } +} + -- cgit v1.2.3 From cc7edda1871c89c7476c67eacf3e6aee56262e2d Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 30 Sep 2019 00:04:18 +0200 Subject: print signal message before exit --- src/sig_handlers.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/sig_handlers.c') diff --git a/src/sig_handlers.c b/src/sig_handlers.c index 601e454..3274482 100644 --- a/src/sig_handlers.c +++ b/src/sig_handlers.c @@ -4,6 +4,7 @@ #include static void abnormal_termination_handler(int signo) { + psignal(signo, ""); exit(signo); } -- cgit v1.2.3