diff --git a/CRT.c b/CRT.c index 7776c4e7..3aea895e 100644 --- a/CRT.c +++ b/CRT.c @@ -552,6 +552,8 @@ void CRT_restorePrivileges() { // TODO: pass an instance of Settings instead. +struct sigaction old_sigsegv_handler; + void CRT_init(int delay, int colorScheme, bool allowUnicode) { initscr(); noecho(); @@ -605,7 +607,11 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { } } #ifndef DEBUG - signal(11, CRT_handleSIGSEGV); + struct sigaction act; + sigemptyset (&act.sa_mask); + act.sa_flags = (int)SA_RESETHAND; + act.sa_handler = CRT_handleSIGSEGV; + sigaction (SIGSEGV, &act, &old_sigsegv_handler); #endif signal(SIGTERM, CRT_handleSIGTERM); signal(SIGQUIT, CRT_handleSIGTERM); diff --git a/CRT.h b/CRT.h index 8a5d6ac6..32992e41 100644 --- a/CRT.h +++ b/CRT.h @@ -108,6 +108,7 @@ typedef enum ColorElements_ { void CRT_fatalError(const char* note) __attribute__ ((noreturn)); +extern struct sigaction old_sigsegv_handler; void CRT_handleSIGSEGV(int sgn); #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) diff --git a/linux/LinuxCRT.c b/linux/LinuxCRT.c index c65b7822..dbfad27f 100644 --- a/linux/LinuxCRT.c +++ b/linux/LinuxCRT.c @@ -7,6 +7,8 @@ in the source distribution for its full text. #include "config.h" #include "CRT.h" + +#include #include #include #ifdef HAVE_EXECINFO_H @@ -32,5 +34,7 @@ void CRT_handleSIGSEGV(int sgn) { fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); #endif - abort(); + + /* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */ + sigaction (SIGSEGV, &old_sigsegv_handler, NULL); }