]> jfr.im git - solanum.git/blame - ircd/ircd_signal.c
extensions/helpops: implement DEHELPER command
[solanum.git] / ircd / ircd_signal.c
CommitLineData
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 */
36static void
37dummy_handler(int sig)
38{
39 /* Empty */
40}
41
42
43static void
44sigchld_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 */
57static void
58sigterm_handler(int sig)
59{
fd5af3d0 60 ircd_shutdown("Received SIGTERM");
212380e3
AC
61}
62
55abcbb2 63/*
212380e3
AC
64 * sighup_handler - reread the server configuration
65 */
66static void
67sighup_handler(int sig)
68{
69 dorehash = 1;
70}
71
72/*
73 * sigusr1_handler - reread the motd file
74 */
75static void
76sigusr1_handler(int sig)
77{
78 doremotd = 1;
79}
80
81static void
82sigusr2_handler(int sig)
83{
84 dorehashbans = 1;
85}
86
87/*
88 * sigint_handler - restart the server
89 */
90static void
91sigint_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 */
114void
115setup_signals()
116{
f8904200 117 sigset_t sigs;
212380e3
AC
118 struct sigaction act;
119
f8904200 120 sigemptyset(&sigs);
212380e3
AC
121 act.sa_flags = 0;
122 act.sa_handler = SIG_IGN;
123 sigemptyset(&act.sa_mask);
124 sigaddset(&act.sa_mask, SIGPIPE);
125 sigaddset(&act.sa_mask, SIGALRM);
126#ifdef SIGTRAP
127 sigaddset(&act.sa_mask, SIGTRAP);
128#endif
129
130# ifdef SIGWINCH
131 sigaddset(&act.sa_mask, SIGWINCH);
132 sigaction(SIGWINCH, &act, 0);
133# endif
134 sigaction(SIGPIPE, &act, 0);
135#ifdef SIGTRAP
136 sigaction(SIGTRAP, &act, 0);
137#endif
138
139 act.sa_handler = dummy_handler;
140 sigaction(SIGALRM, &act, 0);
f8904200 141 sigaddset(&sigs, SIGALRM);
212380e3
AC
142
143 act.sa_handler = sighup_handler;
144 sigemptyset(&act.sa_mask);
145 sigaddset(&act.sa_mask, SIGHUP);
146 sigaction(SIGHUP, &act, 0);
f8904200 147 sigaddset(&sigs, SIGHUP);
212380e3
AC
148
149 act.sa_handler = sigint_handler;
150 sigaddset(&act.sa_mask, SIGINT);
151 sigaction(SIGINT, &act, 0);
f8904200 152 sigaddset(&sigs, SIGINT);
212380e3
AC
153
154 act.sa_handler = sigterm_handler;
155 sigaddset(&act.sa_mask, SIGTERM);
156 sigaction(SIGTERM, &act, 0);
f8904200 157 sigaddset(&sigs, SIGTERM);
212380e3
AC
158
159 act.sa_handler = sigusr1_handler;
160 sigaddset(&act.sa_mask, SIGUSR1);
161 sigaction(SIGUSR1, &act, 0);
f8904200 162 sigaddset(&sigs, SIGUSR1);
212380e3
AC
163
164 act.sa_handler = sigusr2_handler;
165 sigaddset(&act.sa_mask, SIGUSR2);
166 sigaction(SIGUSR2, &act, 0);
f8904200 167 sigaddset(&sigs, SIGUSR2);
212380e3
AC
168
169 act.sa_handler = sigchld_handler;
170 sigaddset(&act.sa_mask, SIGCHLD);
171 sigaction(SIGCHLD, &act, 0);
f8904200 172 sigaddset(&sigs, SIGCHLD);
212380e3 173
f8904200 174 sigprocmask(SIG_UNBLOCK, &sigs, NULL);
212380e3 175}