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