1 |
adx |
30 |
/* |
2 |
michael |
2836 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2836 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
adx |
30 |
* |
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 2 of the License, or |
9 |
|
|
* (at your option) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
|
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2836 |
/*! \file ircd_signal.c.c |
23 |
|
|
* \brief responsible for ircd's signal handling. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
|
|
#include "ircd_signal.h" |
29 |
michael |
2836 |
#include "ircd.h" |
30 |
|
|
#include "restart.h" |
31 |
adx |
30 |
|
32 |
michael |
2836 |
|
33 |
adx |
30 |
/* |
34 |
|
|
* sigterm_handler - exit the server |
35 |
|
|
*/ |
36 |
michael |
2836 |
static void |
37 |
|
|
sigterm_handler(int sig) |
38 |
adx |
30 |
{ |
39 |
michael |
1011 |
server_die("received signal SIGTERM", 0); |
40 |
adx |
30 |
} |
41 |
|
|
|
42 |
michael |
2836 |
/* |
43 |
adx |
30 |
* sighup_handler - reread the server configuration |
44 |
|
|
*/ |
45 |
michael |
2836 |
static void |
46 |
adx |
30 |
sighup_handler(int sig) |
47 |
|
|
{ |
48 |
|
|
dorehash = 1; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
/* |
52 |
|
|
* sigusr1_handler - reread the motd file |
53 |
|
|
*/ |
54 |
|
|
static void |
55 |
|
|
sigusr1_handler(int sig) |
56 |
|
|
{ |
57 |
|
|
doremotd = 1; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
/* |
61 |
michael |
2836 |
* |
62 |
adx |
30 |
* inputs - nothing |
63 |
|
|
* output - nothing |
64 |
|
|
* side effects - Reaps zombies periodically |
65 |
|
|
* -AndroSyn |
66 |
|
|
*/ |
67 |
|
|
static void |
68 |
|
|
sigchld_handler(int sig) |
69 |
|
|
{ |
70 |
michael |
2832 |
int status, errno_save = errno; |
71 |
|
|
|
72 |
|
|
while (waitpid(-1, &status, WNOHANG) > 0) |
73 |
|
|
; |
74 |
|
|
errno = errno_save; |
75 |
adx |
30 |
} |
76 |
|
|
|
77 |
|
|
/* |
78 |
|
|
* sigint_handler - restart the server |
79 |
|
|
*/ |
80 |
michael |
2836 |
static void |
81 |
adx |
30 |
sigint_handler(int sig) |
82 |
|
|
{ |
83 |
michael |
594 |
server_die("SIGINT received", !server_state.foreground); |
84 |
adx |
30 |
} |
85 |
|
|
|
86 |
|
|
/* |
87 |
|
|
* setup_signals - initialize signal handlers for server |
88 |
|
|
*/ |
89 |
michael |
2836 |
void |
90 |
adx |
30 |
setup_signals(void) |
91 |
|
|
{ |
92 |
|
|
struct sigaction act; |
93 |
|
|
|
94 |
|
|
act.sa_flags = 0; |
95 |
|
|
act.sa_handler = SIG_IGN; |
96 |
michael |
594 |
|
97 |
adx |
30 |
sigemptyset(&act.sa_mask); |
98 |
michael |
2834 |
#ifdef SIGXFSZ |
99 |
|
|
sigaddset(&act.sa_mask, SIGXFSZ); |
100 |
|
|
#endif |
101 |
|
|
#ifdef SIGWINCH |
102 |
|
|
sigaddset(&act.sa_mask, SIGWINCH); |
103 |
|
|
#endif |
104 |
adx |
30 |
#ifdef SIGTRAP |
105 |
|
|
sigaddset(&act.sa_mask, SIGTRAP); |
106 |
|
|
#endif |
107 |
michael |
2834 |
sigaddset(&act.sa_mask, SIGPIPE); |
108 |
|
|
sigaddset(&act.sa_mask, SIGALRM); |
109 |
|
|
sigaddset(&act.sa_mask, SIGHUP); |
110 |
|
|
sigaddset(&act.sa_mask, SIGINT); |
111 |
|
|
sigaddset(&act.sa_mask, SIGTERM); |
112 |
|
|
sigaddset(&act.sa_mask, SIGUSR1); |
113 |
|
|
sigaddset(&act.sa_mask, SIGCHLD); |
114 |
|
|
|
115 |
michael |
594 |
#ifdef SIGXFSZ |
116 |
|
|
sigaction(SIGXFSZ, &act, 0); |
117 |
|
|
#endif |
118 |
adx |
30 |
#ifdef SIGWINCH |
119 |
|
|
sigaction(SIGWINCH, &act, 0); |
120 |
|
|
#endif |
121 |
|
|
#ifdef SIGTRAP |
122 |
|
|
sigaction(SIGTRAP, &act, 0); |
123 |
|
|
#endif |
124 |
michael |
2834 |
sigaction(SIGPIPE, &act, 0); |
125 |
|
|
sigaction(SIGALRM, &act, 0); |
126 |
adx |
30 |
|
127 |
|
|
act.sa_handler = sighup_handler; |
128 |
|
|
sigaction(SIGHUP, &act, 0); |
129 |
|
|
|
130 |
|
|
act.sa_handler = sigint_handler; |
131 |
|
|
sigaction(SIGINT, &act, 0); |
132 |
|
|
|
133 |
|
|
act.sa_handler = sigterm_handler; |
134 |
|
|
sigaction(SIGTERM, &act, 0); |
135 |
|
|
|
136 |
|
|
act.sa_handler = sigusr1_handler; |
137 |
|
|
sigaction(SIGUSR1, &act, 0); |
138 |
|
|
|
139 |
|
|
act.sa_handler = sigchld_handler; |
140 |
|
|
sigaction(SIGCHLD, &act, 0); |
141 |
michael |
2834 |
|
142 |
|
|
sigprocmask(SIG_UNBLOCK, &act.sa_mask, NULL); |
143 |
adx |
30 |
} |