]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
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. | |
212380e3 AC |
19 | */ |
20 | ||
21 | #include "stdinc.h" | |
22 | #include "ircd_signal.h" | |
23 | #include "ircd.h" /* dorehash */ | |
24 | #include "restart.h" /* server_reboot */ | |
4016731b | 25 | #include "logger.h" |
212380e3 AC |
26 | #include "s_conf.h" |
27 | #include "client.h" | |
28 | #include "send.h" | |
29 | ||
53e50d0e AC |
30 | #ifndef _WIN32 |
31 | ||
4f5056dd AC |
32 | #include <sys/types.h> |
33 | #include <sys/wait.h> | |
34 | ||
212380e3 AC |
35 | /* |
36 | * dummy_handler - don't know if this is really needed but if alarm is still | |
37 | * being used we probably will | |
38 | */ | |
39 | static void | |
40 | dummy_handler(int sig) | |
41 | { | |
42 | /* Empty */ | |
43 | } | |
44 | ||
45 | ||
46 | static void | |
47 | sigchld_handler(int sig) | |
48 | { | |
3eabb958 JT |
49 | int status, olderrno; |
50 | ||
51 | olderrno = errno; | |
52 | while (waitpid(-1, &status, WNOHANG) > 0) | |
53 | ; | |
54 | errno = olderrno; | |
212380e3 | 55 | } |
3eabb958 | 56 | |
212380e3 AC |
57 | /* |
58 | * sigterm_handler - exit the server | |
59 | */ | |
60 | static void | |
61 | sigterm_handler(int sig) | |
62 | { | |
fd5af3d0 | 63 | ircd_shutdown("Received SIGTERM"); |
212380e3 AC |
64 | } |
65 | ||
55abcbb2 | 66 | /* |
212380e3 AC |
67 | * sighup_handler - reread the server configuration |
68 | */ | |
69 | static void | |
70 | sighup_handler(int sig) | |
71 | { | |
1b916de5 | 72 | dorehash = true; |
212380e3 AC |
73 | } |
74 | ||
75 | /* | |
76 | * sigusr1_handler - reread the motd file | |
77 | */ | |
78 | static void | |
79 | sigusr1_handler(int sig) | |
80 | { | |
1b916de5 | 81 | doremotd = true; |
212380e3 AC |
82 | } |
83 | ||
84 | static void | |
85 | sigusr2_handler(int sig) | |
86 | { | |
1b916de5 | 87 | dorehashbans = true; |
212380e3 AC |
88 | } |
89 | ||
90 | /* | |
91 | * sigint_handler - restart the server | |
92 | */ | |
93 | static void | |
94 | sigint_handler(int sig) | |
95 | { | |
1b916de5 | 96 | static bool restarting = false; |
212380e3 AC |
97 | |
98 | if(server_state_foreground) | |
99 | { | |
100 | ilog(L_MAIN, "Server exiting on SIGINT"); | |
101 | exit(0); | |
102 | } | |
103 | else | |
104 | { | |
105 | ilog(L_MAIN, "Server Restarting on SIGINT"); | |
1b916de5 | 106 | if(!restarting) |
212380e3 | 107 | { |
1b916de5 | 108 | restarting = true; |
212380e3 AC |
109 | server_reboot(); |
110 | } | |
111 | } | |
112 | } | |
113 | ||
114 | /* | |
115 | * setup_signals - initialize signal handlers for server | |
116 | */ | |
117 | void | |
118 | setup_signals() | |
119 | { | |
f8904200 | 120 | sigset_t sigs; |
212380e3 AC |
121 | struct sigaction act; |
122 | ||
f8904200 | 123 | sigemptyset(&sigs); |
212380e3 AC |
124 | act.sa_flags = 0; |
125 | act.sa_handler = SIG_IGN; | |
126 | sigemptyset(&act.sa_mask); | |
127 | sigaddset(&act.sa_mask, SIGPIPE); | |
128 | sigaddset(&act.sa_mask, SIGALRM); | |
129 | #ifdef SIGTRAP | |
130 | sigaddset(&act.sa_mask, SIGTRAP); | |
131 | #endif | |
132 | ||
133 | # ifdef SIGWINCH | |
134 | sigaddset(&act.sa_mask, SIGWINCH); | |
135 | sigaction(SIGWINCH, &act, 0); | |
136 | # endif | |
137 | sigaction(SIGPIPE, &act, 0); | |
138 | #ifdef SIGTRAP | |
139 | sigaction(SIGTRAP, &act, 0); | |
140 | #endif | |
141 | ||
142 | act.sa_handler = dummy_handler; | |
143 | sigaction(SIGALRM, &act, 0); | |
f8904200 | 144 | sigaddset(&sigs, SIGALRM); |
212380e3 AC |
145 | |
146 | act.sa_handler = sighup_handler; | |
147 | sigemptyset(&act.sa_mask); | |
148 | sigaddset(&act.sa_mask, SIGHUP); | |
149 | sigaction(SIGHUP, &act, 0); | |
f8904200 | 150 | sigaddset(&sigs, SIGHUP); |
212380e3 AC |
151 | |
152 | act.sa_handler = sigint_handler; | |
153 | sigaddset(&act.sa_mask, SIGINT); | |
154 | sigaction(SIGINT, &act, 0); | |
f8904200 | 155 | sigaddset(&sigs, SIGINT); |
212380e3 AC |
156 | |
157 | act.sa_handler = sigterm_handler; | |
158 | sigaddset(&act.sa_mask, SIGTERM); | |
159 | sigaction(SIGTERM, &act, 0); | |
f8904200 | 160 | sigaddset(&sigs, SIGTERM); |
212380e3 AC |
161 | |
162 | act.sa_handler = sigusr1_handler; | |
163 | sigaddset(&act.sa_mask, SIGUSR1); | |
164 | sigaction(SIGUSR1, &act, 0); | |
f8904200 | 165 | sigaddset(&sigs, SIGUSR1); |
212380e3 AC |
166 | |
167 | act.sa_handler = sigusr2_handler; | |
168 | sigaddset(&act.sa_mask, SIGUSR2); | |
169 | sigaction(SIGUSR2, &act, 0); | |
f8904200 | 170 | sigaddset(&sigs, SIGUSR2); |
212380e3 AC |
171 | |
172 | act.sa_handler = sigchld_handler; | |
173 | sigaddset(&act.sa_mask, SIGCHLD); | |
174 | sigaction(SIGCHLD, &act, 0); | |
f8904200 | 175 | sigaddset(&sigs, SIGCHLD); |
212380e3 | 176 | |
f8904200 | 177 | sigprocmask(SIG_UNBLOCK, &sigs, NULL); |
212380e3 | 178 | } |
53e50d0e AC |
179 | |
180 | #else | |
181 | void | |
182 | setup_signals() | |
183 | { | |
184 | /* this is a stub for mingw32 */ | |
185 | } | |
186 | ||
187 | void | |
188 | setup_reboot_signals() | |
189 | { | |
190 | /* this is a stub for mingw32 */ | |
191 | } | |
192 | #endif |