Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / ircd_signal.c
1 /*
2  * IRC - Internet Relay Chat, ircd/ircd_signal.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 1, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * $Id$
21  */
22 #include "config.h"
23
24 #include "ircd_signal.h"
25 #include "ircd.h"
26
27 #include <signal.h>
28
29 static struct tag_SignalCounter {
30   unsigned int alrm;
31   unsigned int hup;
32 } SignalCounter;
33
34 void sigalrm_handler(int sig)
35 {
36   ++SignalCounter.alrm;
37 }
38
39 void sigterm_handler(int sig)
40 {
41   server_die("received signal SIGTERM");
42 }
43
44 static void sighup_handler(int sig)
45 {
46   ++SignalCounter.hup;
47   GlobalRehashFlag = 1;
48 }
49
50 static void sigint_handler(int sig)
51 {
52   GlobalRestartFlag = 1;
53 }
54
55 void setup_signals(void)
56 {
57   struct sigaction act;
58
59   act.sa_handler = SIG_IGN;
60   act.sa_flags = 0;
61   sigemptyset(&act.sa_mask);
62   sigaddset(&act.sa_mask, SIGPIPE);
63   sigaddset(&act.sa_mask, SIGALRM);
64 #ifdef  SIGWINCH
65   sigaddset(&act.sa_mask, SIGWINCH);
66   sigaction(SIGWINCH, &act, 0);
67 #endif
68   sigaction(SIGPIPE, &act, 0);
69
70   act.sa_handler = sigalrm_handler;
71   sigaction(SIGALRM, &act, 0);
72
73   sigemptyset(&act.sa_mask);
74
75   act.sa_handler = sighup_handler;
76   sigaction(SIGHUP, &act, 0);
77
78   act.sa_handler = sigint_handler;
79   sigaction(SIGINT, &act, 0);
80
81   act.sa_handler = sigterm_handler;
82   sigaction(SIGTERM, &act, 0);
83
84 #ifdef HAVE_RESTARTABLE_SYSCALLS
85   /*
86    * At least on Apollo sr10.1 it seems continuing system calls
87    * after signal is the default. The following 'siginterrupt'
88    * should change that default to interrupting calls.
89    */
90   siginterrupt(SIGALRM, 1);
91 #endif
92 }
93