]> jfr.im git - solanum.git/blame - ircd/ircd_signal.c
Add a comment explaining match_arrange_stars
[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.
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 */
39static void
40dummy_handler(int sig)
41{
42 /* Empty */
43}
44
45
46static void
47sigchld_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 */
e8399195
AJ
60static void
61sigterm_handler(int sig) __attribute__((noreturn));
62
212380e3
AC
63static void
64sigterm_handler(int sig)
65{
fd5af3d0 66 ircd_shutdown("Received SIGTERM");
212380e3
AC
67}
68
55abcbb2 69/*
212380e3
AC
70 * sighup_handler - reread the server configuration
71 */
72static void
73sighup_handler(int sig)
74{
1b916de5 75 dorehash = true;
212380e3
AC
76}
77
78/*
79 * sigusr1_handler - reread the motd file
80 */
81static void
82sigusr1_handler(int sig)
83{
1b916de5 84 doremotd = true;
212380e3
AC
85}
86
87static void
88sigusr2_handler(int sig)
89{
1b916de5 90 dorehashbans = true;
212380e3
AC
91}
92
93/*
94 * sigint_handler - restart the server
95 */
96static void
97sigint_handler(int sig)
98{
1b916de5 99 static bool restarting = false;
212380e3
AC
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");
1b916de5 109 if(!restarting)
212380e3 110 {
1b916de5 111 restarting = true;
212380e3
AC
112 server_reboot();
113 }
114 }
115}
116
117/*
118 * setup_signals - initialize signal handlers for server
119 */
120void
121setup_signals()
122{
f8904200 123 sigset_t sigs;
212380e3
AC
124 struct sigaction act;
125
f8904200 126 sigemptyset(&sigs);
212380e3
AC
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);
f8904200 147 sigaddset(&sigs, SIGALRM);
212380e3
AC
148
149 act.sa_handler = sighup_handler;
150 sigemptyset(&act.sa_mask);
151 sigaddset(&act.sa_mask, SIGHUP);
152 sigaction(SIGHUP, &act, 0);
f8904200 153 sigaddset(&sigs, SIGHUP);
212380e3
AC
154
155 act.sa_handler = sigint_handler;
156 sigaddset(&act.sa_mask, SIGINT);
157 sigaction(SIGINT, &act, 0);
f8904200 158 sigaddset(&sigs, SIGINT);
212380e3
AC
159
160 act.sa_handler = sigterm_handler;
161 sigaddset(&act.sa_mask, SIGTERM);
162 sigaction(SIGTERM, &act, 0);
f8904200 163 sigaddset(&sigs, SIGTERM);
212380e3
AC
164
165 act.sa_handler = sigusr1_handler;
166 sigaddset(&act.sa_mask, SIGUSR1);
167 sigaction(SIGUSR1, &act, 0);
f8904200 168 sigaddset(&sigs, SIGUSR1);
212380e3
AC
169
170 act.sa_handler = sigusr2_handler;
171 sigaddset(&act.sa_mask, SIGUSR2);
172 sigaction(SIGUSR2, &act, 0);
f8904200 173 sigaddset(&sigs, SIGUSR2);
212380e3
AC
174
175 act.sa_handler = sigchld_handler;
176 sigaddset(&act.sa_mask, SIGCHLD);
177 sigaction(SIGCHLD, &act, 0);
f8904200 178 sigaddset(&sigs, SIGCHLD);
212380e3 179
f8904200 180 sigprocmask(SIG_UNBLOCK, &sigs, NULL);
212380e3 181}
53e50d0e
AC
182
183#else
184void
185setup_signals()
186{
187/* this is a stub for mingw32 */
188}
189
190void
191setup_reboot_signals()
192{
193/* this is a stub for mingw32 */
194}
195#endif