1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* ircd_signal.c: responsible for ircd's signal handling |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "common.h" |
27 |
#include "ircd_signal.h" |
28 |
#include "ircd.h" /* dorehash */ |
29 |
#include "restart.h" /* server_reboot */ |
30 |
#include "s_log.h" |
31 |
#include "memory.h" |
32 |
#include "s_bsd.h" |
33 |
|
34 |
/* |
35 |
* sigterm_handler - exit the server |
36 |
*/ |
37 |
static void |
38 |
sigterm_handler(int sig) |
39 |
{ |
40 |
server_die("received signal SIGTERM", NO); |
41 |
} |
42 |
|
43 |
/* |
44 |
* sighup_handler - reread the server configuration |
45 |
*/ |
46 |
static void |
47 |
sighup_handler(int sig) |
48 |
{ |
49 |
dorehash = 1; |
50 |
} |
51 |
|
52 |
/* |
53 |
* sigusr1_handler - reread the motd file |
54 |
*/ |
55 |
static void |
56 |
sigusr1_handler(int sig) |
57 |
{ |
58 |
doremotd = 1; |
59 |
} |
60 |
|
61 |
/* |
62 |
* |
63 |
* inputs - nothing |
64 |
* output - nothing |
65 |
* side effects - Reaps zombies periodically |
66 |
* -AndroSyn |
67 |
*/ |
68 |
static void |
69 |
sigchld_handler(int sig) |
70 |
{ |
71 |
int status; |
72 |
waitpid(-1, &status, WNOHANG); |
73 |
} |
74 |
|
75 |
/* |
76 |
* sigint_handler - restart the server |
77 |
*/ |
78 |
static void |
79 |
sigint_handler(int sig) |
80 |
{ |
81 |
if (server_state.foreground) |
82 |
server_die("SIGINT received", NO); |
83 |
else |
84 |
restart("SIGINT received"); |
85 |
} |
86 |
|
87 |
/* |
88 |
* setup_signals - initialize signal handlers for server |
89 |
*/ |
90 |
void |
91 |
setup_signals(void) |
92 |
{ |
93 |
struct sigaction act; |
94 |
|
95 |
act.sa_flags = 0; |
96 |
act.sa_handler = SIG_IGN; |
97 |
sigemptyset(&act.sa_mask); |
98 |
sigaddset(&act.sa_mask, SIGPIPE); |
99 |
sigaddset(&act.sa_mask, SIGALRM); |
100 |
#ifdef SIGTRAP |
101 |
sigaddset(&act.sa_mask, SIGTRAP); |
102 |
#endif |
103 |
|
104 |
#ifdef SIGWINCH |
105 |
sigaddset(&act.sa_mask, SIGWINCH); |
106 |
sigaction(SIGWINCH, &act, 0); |
107 |
#endif |
108 |
sigaction(SIGPIPE, &act, 0); |
109 |
#ifdef SIGTRAP |
110 |
sigaction(SIGTRAP, &act, 0); |
111 |
#endif |
112 |
|
113 |
act.sa_handler = sighup_handler; |
114 |
sigemptyset(&act.sa_mask); |
115 |
sigaddset(&act.sa_mask, SIGHUP); |
116 |
sigaction(SIGHUP, &act, 0); |
117 |
|
118 |
act.sa_handler = sigint_handler; |
119 |
sigaddset(&act.sa_mask, SIGINT); |
120 |
sigaction(SIGINT, &act, 0); |
121 |
|
122 |
act.sa_handler = sigterm_handler; |
123 |
sigaddset(&act.sa_mask, SIGTERM); |
124 |
sigaction(SIGTERM, &act, 0); |
125 |
|
126 |
act.sa_handler = sigusr1_handler; |
127 |
sigaddset(&act.sa_mask, SIGUSR1); |
128 |
sigaction(SIGUSR1, &act, 0); |
129 |
|
130 |
act.sa_handler = sigchld_handler; |
131 |
sigaddset(&act.sa_mask, SIGCHLD); |
132 |
sigaction(SIGCHLD, &act, 0); |
133 |
} |