Author: Isomer / ZenShadow
[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 "ircd_signal.h"
23 #include "ircd.h"
24
25 #include <signal.h>
26
27 static struct tag_SignalCounter {
28   unsigned int alrm;
29   unsigned int hup;
30 } SignalCounter;
31
32 void sigalrm_handler(int sig)
33 {
34   ++SignalCounter.alrm;
35 }
36
37 void sigterm_handler(int sig)
38 {
39   server_die("received signal SIGTERM");
40 }
41
42 static void sighup_handler(int sig)
43 {
44   ++SignalCounter.hup;
45   GlobalRehashFlag = 1;
46 }
47
48 static void sigint_handler(int sig)
49 {
50   GlobalRestartFlag = 1;
51 }
52
53 void setup_signals(void)
54 {
55   struct sigaction act;
56
57   act.sa_handler = SIG_IGN;
58   act.sa_flags = 0;
59   sigemptyset(&act.sa_mask);
60   sigaddset(&act.sa_mask, SIGPIPE);
61   sigaddset(&act.sa_mask, SIGALRM);
62 #ifdef  SIGWINCH
63   sigaddset(&act.sa_mask, SIGWINCH);
64   sigaction(SIGWINCH, &act, 0);
65 #endif
66   sigaction(SIGPIPE, &act, 0);
67
68   act.sa_handler = sigalrm_handler;
69   sigaction(SIGALRM, &act, 0);
70
71   sigemptyset(&act.sa_mask);
72
73   act.sa_handler = sighup_handler;
74   sigaction(SIGHUP, &act, 0);
75
76   act.sa_handler = sigint_handler;
77   sigaction(SIGINT, &act, 0);
78
79   act.sa_handler = sigterm_handler;
80   sigaction(SIGTERM, &act, 0);
81
82 #ifdef HAVE_RESTARTABLE_SYSCALLS
83   /*
84    * At least on Apollo sr10.1 it seems continuing system calls
85    * after signal is the default. The following 'siginterrupt'
86    * should change that default to interrupting calls.
87    */
88   siginterrupt(SIGALRM, 1);
89 #endif
90 }
91