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/dged/keyboard.c | 2 +- src/main/main.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/dged/keyboard.c b/src/dged/keyboard.c index f13d449..1e28066 100644 --- a/src/dged/keyboard.c +++ b/src/dged/keyboard.c @@ -108,7 +108,7 @@ struct keyboard_update keyboard_update(struct keyboard *kbd, } // read all input in chunks of `bufsize` bytes - const uint32_t bufsize = 128; + const uint32_t bufsize = 1024; uint8_t *buf = malloc(bufsize), *writepos = buf; int nbytes = 0, nread = 0; while ((nread = read(kbd->fd, writepos, bufsize)) == bufsize) { 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