ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/ircd_signal.c
Revision: 2834
Committed: Thu Jan 16 17:54:09 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 3128 byte(s)
Log Message:
- ircd_signal.c:setup_signals(): fixed bug where signals stopped from
  working after restaring the ircd via SIGINT. Spotted and fixed by Adam.

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #include "ircd_signal.h"
28     #include "ircd.h" /* dorehash */
29 michael 594 #include "restart.h" /* server_die */
30 adx 30 #include "memory.h"
31     #include "s_bsd.h"
32    
33     /*
34     * sigterm_handler - exit the server
35     */
36     static void
37     sigterm_handler(int sig)
38     {
39 michael 1011 server_die("received signal SIGTERM", 0);
40 adx 30 }
41    
42     /*
43     * sighup_handler - reread the server configuration
44     */
45     static void
46     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     *
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 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     static void
81     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     void
90     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 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision