]>
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. | |
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 */ | |
4016731b | 27 | #include "logger.h" |
212380e3 AC |
28 | #include "s_conf.h" |
29 | #include "client.h" | |
30 | #include "send.h" | |
31 | ||
32 | /* | |
33 | * dummy_handler - don't know if this is really needed but if alarm is still | |
34 | * being used we probably will | |
35 | */ | |
36 | static void | |
37 | dummy_handler(int sig) | |
38 | { | |
39 | /* Empty */ | |
40 | } | |
41 | ||
42 | ||
43 | static void | |
44 | sigchld_handler(int sig) | |
45 | { | |
3eabb958 JT |
46 | int status, olderrno; |
47 | ||
48 | olderrno = errno; | |
49 | while (waitpid(-1, &status, WNOHANG) > 0) | |
50 | ; | |
51 | errno = olderrno; | |
212380e3 | 52 | } |
3eabb958 | 53 | |
212380e3 AC |
54 | /* |
55 | * sigterm_handler - exit the server | |
56 | */ | |
57 | static void | |
58 | sigterm_handler(int sig) | |
59 | { | |
fd5af3d0 | 60 | ircd_shutdown("Received SIGTERM"); |
212380e3 AC |
61 | } |
62 | ||
63 | /* | |
64 | * sighup_handler - reread the server configuration | |
65 | */ | |
66 | static void | |
67 | sighup_handler(int sig) | |
68 | { | |
69 | dorehash = 1; | |
70 | } | |
71 | ||
72 | /* | |
73 | * sigusr1_handler - reread the motd file | |
74 | */ | |
75 | static void | |
76 | sigusr1_handler(int sig) | |
77 | { | |
78 | doremotd = 1; | |
79 | } | |
80 | ||
81 | static void | |
82 | sigusr2_handler(int sig) | |
83 | { | |
84 | dorehashbans = 1; | |
85 | } | |
86 | ||
87 | /* | |
88 | * sigint_handler - restart the server | |
89 | */ | |
90 | static void | |
91 | sigint_handler(int sig) | |
92 | { | |
93 | static int restarting = 0; | |
94 | ||
95 | if(server_state_foreground) | |
96 | { | |
97 | ilog(L_MAIN, "Server exiting on SIGINT"); | |
98 | exit(0); | |
99 | } | |
100 | else | |
101 | { | |
102 | ilog(L_MAIN, "Server Restarting on SIGINT"); | |
103 | if(restarting == 0) | |
104 | { | |
105 | restarting = 1; | |
106 | server_reboot(); | |
107 | } | |
108 | } | |
109 | } | |
110 | ||
111 | /* | |
112 | * setup_signals - initialize signal handlers for server | |
113 | */ | |
114 | void | |
115 | setup_signals() | |
116 | { | |
117 | struct sigaction act; | |
118 | ||
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); | |
139 | ||
140 | act.sa_handler = sighup_handler; | |
141 | sigemptyset(&act.sa_mask); | |
142 | sigaddset(&act.sa_mask, SIGHUP); | |
143 | sigaction(SIGHUP, &act, 0); | |
144 | ||
145 | act.sa_handler = sigint_handler; | |
146 | sigaddset(&act.sa_mask, SIGINT); | |
147 | sigaction(SIGINT, &act, 0); | |
148 | ||
149 | act.sa_handler = sigterm_handler; | |
150 | sigaddset(&act.sa_mask, SIGTERM); | |
151 | sigaction(SIGTERM, &act, 0); | |
152 | ||
153 | act.sa_handler = sigusr1_handler; | |
154 | sigaddset(&act.sa_mask, SIGUSR1); | |
155 | sigaction(SIGUSR1, &act, 0); | |
156 | ||
157 | act.sa_handler = sigusr2_handler; | |
158 | sigaddset(&act.sa_mask, SIGUSR2); | |
159 | sigaction(SIGUSR2, &act, 0); | |
160 | ||
161 | act.sa_handler = sigchld_handler; | |
162 | sigaddset(&act.sa_mask, SIGCHLD); | |
163 | sigaction(SIGCHLD, &act, 0); | |
164 | ||
165 | } |