Restore stats_spy hook that was removed in commit 401f2454671ca233e35b0e6e4f3fa4c43cd...
[seven-1.x.git] / src / ircd_signal.c
blob77163b4c3220d08d9bb83678e66b82d58f18657c
1 /************************************************************************
2 * IRC - Internet Relay Chat, src/ircd_signal.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
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.
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.
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.
22 #include "stdinc.h"
23 #include "ircd_signal.h"
24 #include "ircd.h" /* dorehash */
25 #include "restart.h" /* server_reboot */
26 #include "s_log.h"
27 #include "memory.h"
28 #include "commio.h"
29 #include "s_conf.h"
30 #include "client.h"
31 #include "send.h"
34 * dummy_handler - don't know if this is really needed but if alarm is still
35 * being used we probably will
37 static void
38 dummy_handler(int sig)
40 /* Empty */
44 static void
45 sigchld_handler(int sig)
47 int status;
48 waitpid(-1, &status, WNOHANG);
51 * sigterm_handler - exit the server
53 static void
54 sigterm_handler(int sig)
56 /* XXX we had a flush_connections() here - we should close all the
57 * connections and flush data. read server_reboot() for my explanation.
58 * -- adrian
60 ilog(L_MAIN, "Server killed By SIGTERM");
61 exit(-1);
64 /*
65 * sighup_handler - reread the server configuration
67 static void
68 sighup_handler(int sig)
70 dorehash = 1;
74 * sigusr1_handler - reread the motd file
76 static void
77 sigusr1_handler(int sig)
79 doremotd = 1;
82 static void
83 sigusr2_handler(int sig)
85 dorehashbans = 1;
89 * sigint_handler - restart the server
91 static void
92 sigint_handler(int sig)
94 static int restarting = 0;
96 if(server_state_foreground)
98 ilog(L_MAIN, "Server exiting on SIGINT");
99 exit(0);
101 else
103 ilog(L_MAIN, "Server Restarting on SIGINT");
104 if(restarting == 0)
106 restarting = 1;
107 server_reboot();
113 * setup_signals - initialize signal handlers for server
115 void
116 setup_signals()
118 struct sigaction act;
120 act.sa_flags = 0;
121 act.sa_handler = SIG_IGN;
122 sigemptyset(&act.sa_mask);
123 sigaddset(&act.sa_mask, SIGPIPE);
124 sigaddset(&act.sa_mask, SIGALRM);
125 #ifdef SIGTRAP
126 sigaddset(&act.sa_mask, SIGTRAP);
127 #endif
129 # ifdef SIGWINCH
130 sigaddset(&act.sa_mask, SIGWINCH);
131 sigaction(SIGWINCH, &act, 0);
132 # endif
133 sigaction(SIGPIPE, &act, 0);
134 #ifdef SIGTRAP
135 sigaction(SIGTRAP, &act, 0);
136 #endif
138 act.sa_handler = dummy_handler;
139 sigaction(SIGALRM, &act, 0);
141 act.sa_handler = sighup_handler;
142 sigemptyset(&act.sa_mask);
143 sigaddset(&act.sa_mask, SIGHUP);
144 sigaction(SIGHUP, &act, 0);
146 act.sa_handler = sigint_handler;
147 sigaddset(&act.sa_mask, SIGINT);
148 sigaction(SIGINT, &act, 0);
150 act.sa_handler = sigterm_handler;
151 sigaddset(&act.sa_mask, SIGTERM);
152 sigaction(SIGTERM, &act, 0);
154 act.sa_handler = sigusr1_handler;
155 sigaddset(&act.sa_mask, SIGUSR1);
156 sigaction(SIGUSR1, &act, 0);
158 act.sa_handler = sigusr2_handler;
159 sigaddset(&act.sa_mask, SIGUSR2);
160 sigaction(SIGUSR2, &act, 0);
162 act.sa_handler = sigchld_handler;
163 sigaddset(&act.sa_mask, SIGCHLD);
164 sigaction(SIGCHLD, &act, 0);