]> jfr.im git - irc/rqf/shadowircd.git/blob - src/ircd_signal.c
[svn] - the new plan:
[irc/rqf/shadowircd.git] / src / ircd_signal.c
1 /************************************************************************
2 * IRC - Internet Relay Chat, src/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: ircd_signal.c 6 2005-09-10 01:02:21Z nenolod $
21 */
22
23 #include "stdinc.h"
24 #include "ircd_signal.h"
25 #include "ircd.h" /* dorehash */
26 #include "restart.h" /* server_reboot */
27 #include "s_log.h"
28 #include "memory.h"
29 #include "commio.h"
30 #include "s_conf.h"
31 #include "client.h"
32 #include "send.h"
33
34 /*
35 * dummy_handler - don't know if this is really needed but if alarm is still
36 * being used we probably will
37 */
38 static void
39 dummy_handler(int sig)
40 {
41 /* Empty */
42 }
43
44
45 static void
46 sigchld_handler(int sig)
47 {
48 int status;
49 waitpid(-1, &status, WNOHANG);
50 }
51 /*
52 * sigterm_handler - exit the server
53 */
54 static void
55 sigterm_handler(int sig)
56 {
57 /* XXX we had a flush_connections() here - we should close all the
58 * connections and flush data. read server_reboot() for my explanation.
59 * -- adrian
60 */
61 ilog(L_MAIN, "Server killed By SIGTERM");
62 exit(-1);
63 }
64
65 /*
66 * sighup_handler - reread the server configuration
67 */
68 static void
69 sighup_handler(int sig)
70 {
71 dorehash = 1;
72 }
73
74 /*
75 * sigusr1_handler - reread the motd file
76 */
77 static void
78 sigusr1_handler(int sig)
79 {
80 doremotd = 1;
81 }
82
83 static void
84 sigusr2_handler(int sig)
85 {
86 dorehashbans = 1;
87 }
88
89 /*
90 * sigint_handler - restart the server
91 */
92 static void
93 sigint_handler(int sig)
94 {
95 static int restarting = 0;
96
97 if(server_state_foreground)
98 {
99 ilog(L_MAIN, "Server exiting on SIGINT");
100 exit(0);
101 }
102 else
103 {
104 ilog(L_MAIN, "Server Restarting on SIGINT");
105 if(restarting == 0)
106 {
107 restarting = 1;
108 server_reboot();
109 }
110 }
111 }
112
113 /*
114 * setup_signals - initialize signal handlers for server
115 */
116 void
117 setup_signals()
118 {
119 struct sigaction act;
120
121 act.sa_flags = 0;
122 act.sa_handler = SIG_IGN;
123 sigemptyset(&act.sa_mask);
124 sigaddset(&act.sa_mask, SIGPIPE);
125 sigaddset(&act.sa_mask, SIGALRM);
126 #ifdef SIGTRAP
127 sigaddset(&act.sa_mask, SIGTRAP);
128 #endif
129
130 # ifdef SIGWINCH
131 sigaddset(&act.sa_mask, SIGWINCH);
132 sigaction(SIGWINCH, &act, 0);
133 # endif
134 sigaction(SIGPIPE, &act, 0);
135 #ifdef SIGTRAP
136 sigaction(SIGTRAP, &act, 0);
137 #endif
138
139 act.sa_handler = dummy_handler;
140 sigaction(SIGALRM, &act, 0);
141
142 act.sa_handler = sighup_handler;
143 sigemptyset(&act.sa_mask);
144 sigaddset(&act.sa_mask, SIGHUP);
145 sigaction(SIGHUP, &act, 0);
146
147 act.sa_handler = sigint_handler;
148 sigaddset(&act.sa_mask, SIGINT);
149 sigaction(SIGINT, &act, 0);
150
151 act.sa_handler = sigterm_handler;
152 sigaddset(&act.sa_mask, SIGTERM);
153 sigaction(SIGTERM, &act, 0);
154
155 act.sa_handler = sigusr1_handler;
156 sigaddset(&act.sa_mask, SIGUSR1);
157 sigaction(SIGUSR1, &act, 0);
158
159 act.sa_handler = sigusr2_handler;
160 sigaddset(&act.sa_mask, SIGUSR2);
161 sigaction(SIGUSR2, &act, 0);
162
163 act.sa_handler = sigchld_handler;
164 sigaddset(&act.sa_mask, SIGCHLD);
165 sigaction(SIGCHLD, &act, 0);
166
167 }