From 98f8b3709355fd0f3e05952cee3ec54ec2d0b5ba Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 5 Oct 2006 20:26:44 +0000 Subject: exit gracefully on fatal signals (with nongraceful code...signals suck!) --- fbcon.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fbcon.c b/fbcon.c index e92b063..7f0fb63 100644 --- a/fbcon.c +++ b/fbcon.c @@ -61,6 +61,15 @@ static int get_fb_size(struct uudisp *d) return 0; } +static struct uudisp *display; + +static void fatalsignal(int sig) +{ + uudisp_close(display); + signal(sig, SIG_DFL); + raise(sig); +} + static void dummy(int x) { } @@ -185,6 +194,14 @@ int uudisp_open(struct uudisp *d) signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); + display = d; + signal(SIGINT, fatalsignal); + signal(SIGTERM, fatalsignal); + signal(SIGSEGV, fatalsignal); + signal(SIGBUS, fatalsignal); + signal(SIGABRT, fatalsignal); + signal(SIGFPE, fatalsignal); + return 0; error: if (p->b.vidmem != MAP_FAILED) munmap(p->b.vidmem, fix.smem_len); -- cgit v1.2.3