catpoint

Catpoint simple presenting software.
git clone git://r-36.net/catpoint
Log | Files | Refs | LICENSE

commit 62d8733dfbae0ee35a6d71a77409e8bc33f2b8f8
parent 05fee79d9bfcc4029064723a9739dbeedf8fb788
Author: KatolaZ <katolaz@freaknet.org>
Date:   Sun,  8 Jul 2018 14:54:37 +0200

patch signal handlers for catpoint

As subject says. Avoid to garble the terminal on an exit due to
signal. Quite straightforward ;)

HND

KatolaZ

--
[ ~.,_  Enzo Nicosia aka KatolaZ - Devuan -- Freaknet Medialab  ]
[     "+.  katolaz [at] freaknet.org --- katolaz [at] yahoo.it  ]
[       @)   http://kalos.mine.nu ---  Devuan GNU + Linux User  ]
[     @@)  http://maths.qmul.ac.uk/~vnicosia --  GPG: 0B5F062F  ]
[ (@@@)  Twitter: @KatolaZ - skype: katolaz -- github: KatolaZ  ]

Signed-off-by: Christoph Lohmann <20h@r-36.net>

Diffstat:
catpoint.c | 37++++++++++++++++++++++++++++++++-----
1 file changed, 32 insertions(+), 5 deletions(-)

diff --git a/catpoint.c b/catpoint.c @@ -10,21 +10,51 @@ #include <stdlib.h> #include <unistd.h> #include <locale.h> +#include <signal.h> + +char **p; /* the slides */ +int n; /* the number of slides */ + +void +cleanup(int s) +{ + int i; + for (i = 0; i<n; i++) + munmap(p[i], 0x1000); + + endwin(); /* restore terminal */ + exit(1); +} + + +void +setsignal() +{ + signal(SIGHUP, cleanup); + signal(SIGINT, cleanup); + signal(SIGINT, cleanup); + signal(SIGQUIT, cleanup); + signal(SIGABRT, cleanup); + signal(SIGKILL, cleanup); + signal(SIGTERM, cleanup); +} + int main(int argc, char *argv[]) { int c, i, fd; - char **p; /* the slides */ if (argc == 1) errx(1, "usage: %s file ...", argv[0]); argv++; argc--; + setsignal(); setlocale(LC_ALL, ""); p = calloc(argc, sizeof(char *)); + n = argc; /* map files to mem */ for (i = 0; argv[i] != NULL; i++) { @@ -102,10 +132,7 @@ again: } /* unmap mem */ - for (i = 0; argv[i] != NULL; i++) - munmap(p[i], 0x1000); - - endwin(); /* restore terminal */ + cleanup(0); return (0); }