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