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>
This commit is contained in:
KatolaZ 2018-07-08 14:54:37 +02:00 committed by Christoph Lohmann
parent 05fee79d9b
commit 62d8733dfb

View File

@ -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);
}