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