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>master
parent
05fee79d9b
commit
62d8733dfb
37
catpoint.c
37
catpoint.c
|
@ -10,21 +10,51 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <locale.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
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int c, i, fd;
|
int c, i, fd;
|
||||||
char **p; /* the slides */
|
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
errx(1, "usage: %s file ...", argv[0]);
|
errx(1, "usage: %s file ...", argv[0]);
|
||||||
argv++;
|
argv++;
|
||||||
argc--;
|
argc--;
|
||||||
|
|
||||||
|
setsignal();
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
p = calloc(argc, sizeof(char *));
|
p = calloc(argc, sizeof(char *));
|
||||||
|
n = argc;
|
||||||
|
|
||||||
/* map files to mem */
|
/* map files to mem */
|
||||||
for (i = 0; argv[i] != NULL; i++) {
|
for (i = 0; argv[i] != NULL; i++) {
|
||||||
|
@ -102,10 +132,7 @@ again:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* unmap mem */
|
/* unmap mem */
|
||||||
for (i = 0; argv[i] != NULL; i++)
|
cleanup(0);
|
||||||
munmap(p[i], 0x1000);
|
|
||||||
|
|
||||||
endwin(); /* restore terminal */
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue