move signal functions into own file
[vlock.git] / src / signals.c
blob8d0b9ae4933dba8bfc69a3e0784f7fb004a798b2
1 #define _GNU_SOURCE
2 #include <stdio.h>
4 #include <signal.h>
6 #include <string.h>
8 void invoke_atexit_functions(void);
10 static void terminate(int signum)
12 invoke_atexit_functions();
13 fprintf(stderr, "vlock: Killed by signal %d (%s)!\n", signum, strsignal(signum));
14 raise(signum);
17 void install_signal_handlers(void)
19 struct sigaction sa;
21 /* Ignore some signals. */
22 (void) sigemptyset(&(sa.sa_mask));
23 sa.sa_flags = SA_RESTART;
24 sa.sa_handler = SIG_IGN;
25 (void) sigaction(SIGTSTP, &sa, NULL);
27 /* Handle termination signals. None of these should be delivered in a normal
28 * run of the program because terminal signals (INT, QUIT) are disabled
29 * below. */
30 sa.sa_flags = SA_RESETHAND;
31 sa.sa_handler = terminate;
32 (void) sigaction(SIGINT, &sa, NULL);
33 (void) sigaction(SIGQUIT, &sa, NULL);
34 (void) sigaction(SIGTERM, &sa, NULL);
35 (void) sigaction(SIGHUP, &sa, NULL);
36 (void) sigaction(SIGABRT, &sa, NULL);
37 (void) sigaction(SIGSEGV, &sa, NULL);