From 1c78990eef67e89cfb2d664415c52a6a4009fa9c Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Fri, 22 Mar 2024 20:53:20 +0100 Subject: Add a sigsegv handler To try and reset the terminal to something useful. --- src/main/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main/main.c') diff --git a/src/main/main.c b/src/main/main.c index b96edd4..a1703ce 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -53,6 +53,18 @@ void resized() { signal(SIGWINCH, resized); } +void segfault() { + // make an effort to restore the + // terminal to its former glory + if (display != NULL) { + display_clear(display); + display_destroy(display); + } + + printf("Segfault encountered...\n"); + abort(); +} + #define INVALID_WATCH -1 struct watched_file { uint32_t watch_id; @@ -156,6 +168,7 @@ int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); signal(SIGTERM, terminate); + signal(SIGSEGV, segfault); struct commands commands = command_registry_create(32); -- cgit v1.2.3