summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-03-22 20:53:20 +0100
committerAlbert Cervin <albert@acervin.com>2024-03-22 20:55:36 +0100
commit1c78990eef67e89cfb2d664415c52a6a4009fa9c (patch)
tree25a1ced9ea743a1b24794da558b6cb87d44b63ab /src/main
parentbb2dff871b6a5b1362a2f867e586b06dc6b49996 (diff)
downloaddged-1c78990eef67e89cfb2d664415c52a6a4009fa9c.tar.gz
dged-1c78990eef67e89cfb2d664415c52a6a4009fa9c.tar.xz
dged-1c78990eef67e89cfb2d664415c52a6a4009fa9c.zip
Add a sigsegv handler
To try and reset the terminal to something useful.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/main.c13
1 files changed, 13 insertions, 0 deletions
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);