1 /************************************************************************
2 * IRC - Internet Relay Chat, src/ircd_signal.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
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)
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.
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.
20 * $Id: ircd_signal.c 26 2006-09-20 18:02:06Z spb $
24 #include "ircd_signal.h"
25 #include "ircd.h" /* dorehash */
26 #include "restart.h" /* server_reboot */
35 * dummy_handler - don't know if this is really needed but if alarm is still
36 * being used we probably will
39 dummy_handler(int sig
)
46 sigchld_handler(int sig
)
49 waitpid(-1, &status
, WNOHANG
);
52 * sigterm_handler - exit the server
55 sigterm_handler(int sig
)
57 /* XXX we had a flush_connections() here - we should close all the
58 * connections and flush data. read server_reboot() for my explanation.
61 ilog(L_MAIN
, "Server killed By SIGTERM");
66 * sighup_handler - reread the server configuration
69 sighup_handler(int sig
)
75 * sigusr1_handler - reread the motd file
78 sigusr1_handler(int sig
)
84 sigusr2_handler(int sig
)
90 * sigint_handler - restart the server
93 sigint_handler(int sig
)
95 static int restarting
= 0;
97 if(server_state_foreground
)
99 ilog(L_MAIN
, "Server exiting on SIGINT");
104 ilog(L_MAIN
, "Server Restarting on SIGINT");
114 * setup_signals - initialize signal handlers for server
119 struct sigaction act
;
122 act
.sa_handler
= SIG_IGN
;
123 sigemptyset(&act
.sa_mask
);
124 sigaddset(&act
.sa_mask
, SIGPIPE
);
125 sigaddset(&act
.sa_mask
, SIGALRM
);
127 sigaddset(&act
.sa_mask
, SIGTRAP
);
131 sigaddset(&act
.sa_mask
, SIGWINCH
);
132 sigaction(SIGWINCH
, &act
, 0);
134 sigaction(SIGPIPE
, &act
, 0);
136 sigaction(SIGTRAP
, &act
, 0);
139 act
.sa_handler
= dummy_handler
;
140 sigaction(SIGALRM
, &act
, 0);
142 act
.sa_handler
= sighup_handler
;
143 sigemptyset(&act
.sa_mask
);
144 sigaddset(&act
.sa_mask
, SIGHUP
);
145 sigaction(SIGHUP
, &act
, 0);
147 act
.sa_handler
= sigint_handler
;
148 sigaddset(&act
.sa_mask
, SIGINT
);
149 sigaction(SIGINT
, &act
, 0);
151 act
.sa_handler
= sigterm_handler
;
152 sigaddset(&act
.sa_mask
, SIGTERM
);
153 sigaction(SIGTERM
, &act
, 0);
155 act
.sa_handler
= sigusr1_handler
;
156 sigaddset(&act
.sa_mask
, SIGUSR1
);
157 sigaction(SIGUSR1
, &act
, 0);
159 act
.sa_handler
= sigusr2_handler
;
160 sigaddset(&act
.sa_mask
, SIGUSR2
);
161 sigaction(SIGUSR2
, &act
, 0);
163 act
.sa_handler
= sigchld_handler
;
164 sigaddset(&act
.sa_mask
, SIGCHLD
);
165 sigaction(SIGCHLD
, &act
, 0);