Author: Bleep <tomh@inxpress.net>
[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 #ifdef PROFIL
33 void s_monitor(int sig)
34 {
35   static int mon = 0;
36
37   moncontrol(mon);
38   mon = 1 - mon;
39 }
40
41 #endif
42
43 void sigalrm_handler(int sig)
44 {
45   ++SignalCounter.alrm;
46 }
47
48 void sigterm_handler(int sig)
49 {
50   server_die("received signal SIGTERM");
51 }
52
53 static void sighup_handler(int sig)
54 {
55   ++SignalCounter.hup;
56   GlobalRehashFlag = 1;
57 }
58
59 static void sigint_handler(int sig)
60 {
61   GlobalRestartFlag = 1;
62 }
63
64 void setup_signals(void)
65 {
66   struct sigaction act;
67
68   act.sa_handler = SIG_IGN;
69   act.sa_flags = 0;
70   sigemptyset(&act.sa_mask);
71   sigaddset(&act.sa_mask, SIGPIPE);
72   sigaddset(&act.sa_mask, SIGALRM);
73 #ifdef  SIGWINCH
74   sigaddset(&act.sa_mask, SIGWINCH);
75   sigaction(SIGWINCH, &act, 0);
76 #endif
77   sigaction(SIGPIPE, &act, 0);
78
79   act.sa_handler = sigalrm_handler;
80   sigaction(SIGALRM, &act, 0);
81
82   sigemptyset(&act.sa_mask);
83
84   act.sa_handler = sighup_handler;
85   sigaction(SIGHUP, &act, 0);
86
87   act.sa_handler = sigint_handler;
88   sigaction(SIGINT, &act, 0);
89
90   act.sa_handler = sigterm_handler;
91   sigaction(SIGTERM, &act, 0);
92
93 #ifdef HAVE_RESTARTABLE_SYSCALLS
94   /*
95    * At least on Apollo sr10.1 it seems continuing system calls
96    * after signal is the default. The following 'siginterrupt'
97    * should change that default to interrupting calls.
98    */
99   siginterrupt(SIGALRM, 1);
100 #endif
101 }
102