1 /*
2  * signals.c
3  * (C)1999-2011 by Marc Huber <Marc.Huber@web.de>
4  * All rights reserved.
5  *
6  * $Id: signals.c,v 1.11 2015/03/14 06:11:31 marc Exp marc $
7  *
8  */
9 
10 #include "headers.h"
11 #include <signal.h>
12 #include <sysexits.h>
13 
14 static const char rcsid[] __attribute__ ((used)) = "$Id: signals.c,v 1.11 2015/03/14 06:11:31 marc Exp marc $";
15 
16 static sigset_t master_set;
17 
catchhup(int i)18 void catchhup(int i __attribute__ ((unused)))
19 {
20     signal(SIGHUP, SIG_IGN);
21     signal(SIGTERM, SIG_IGN);
22 
23     cleanup(ctx_spawnd, 0);
24     die_when_idle = -1;
25     logmsg("SIGHUP: No longer accepting new connections.");
26 
27     set_proctitle(ACCEPT_NEVER);
28 }
29 
setup_signals()30 void setup_signals()
31 {
32     signal(SIGPIPE, SIG_IGN);
33     signal(SIGCHLD, SIG_IGN);
34     signal(SIGHUP, catchhup);
35     signal(SIGTERM, catchhup);
36     sigfillset(&master_set);
37     sigdelset(&master_set, SIGSEGV);
38     sigprocmask(SIG_SETMASK, &master_set, NULL);
39 }
40 
process_signals()41 void process_signals()
42 {
43     sigprocmask(SIG_UNBLOCK, &master_set, NULL);
44     sigprocmask(SIG_SETMASK, &master_set, NULL);
45 }
46