Merge branch 'canoe' into vlock-2
[vlock.git] / src / signals.c
blob70cc5d785f28f8d7ae21a845aa914df6ba08b189
1 #define _GNU_SOURCE
2 #include <stdio.h>
4 #include <signal.h>
6 #include <string.h>
8 #include "signals.h"
9 #include "util.h"
11 static const char *termination_blurb =
12 "\n"
13 "*******************************************************************************\n"
14 "*** vlock caught a fatal signal and will now terminate. The reason for ***\n"
15 "*** this is very likely an error in the program. Please notify the author ***\n"
16 "*** about this problem by sending an email to the address below. Include ***\n"
17 "*** all messages leading up to this one and as much information as possible ***\n"
18 "*** about your system and configuration. ***\n"
19 "*** Please include the word \"vlock\" in the subject of your email. Sorry ***\n"
20 "*** for any inconvenience. ***\n"
21 "*** ***\n"
22 "*** Frank Benkstein <frank-vlock@benkstein.net> ***\n"
23 "*******************************************************************************\n"
24 "\n"
27 static void terminate(int signum)
29 vlock_invoke_atexit();
31 fprintf(stderr, "vlock: Killed by signal %d (%s)!\n", signum,
32 strsignal(signum));
34 if (signum != SIGTERM)
35 fputs(termination_blurb, stderr);
37 raise(signum);
40 void install_signal_handlers(void)
42 struct sigaction sa;
44 /* Ignore some signals. */
45 (void) sigemptyset(&(sa.sa_mask));
46 sa.sa_flags = SA_RESTART;
47 sa.sa_handler = SIG_IGN;
48 (void) sigaction(SIGTSTP, &sa, NULL);
50 /* Handle termination signals. None of these should be delivered in a normal
51 * run of the program because terminal signals (INT, QUIT) are disabled
52 * below. */
53 sa.sa_flags = SA_RESETHAND;
54 sa.sa_handler = terminate;
55 (void) sigaction(SIGINT, &sa, NULL);
56 (void) sigaction(SIGQUIT, &sa, NULL);
57 (void) sigaction(SIGTERM, &sa, NULL);
58 (void) sigaction(SIGHUP, &sa, NULL);
59 (void) sigaction(SIGABRT, &sa, NULL);
60 (void) sigaction(SIGSEGV, &sa, NULL);