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