2 * IRC - Internet Relay Chat, ircd/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.
21 * @brief Signal handlers for ircu.
27 #include "ircd_events.h"
28 #include "ircd_signal.h"
34 /** Counts various types of signals that we receive. */
35 static struct tag_SignalCounter {
36 unsigned int alrm; /**< Received SIGALRM count. */
37 unsigned int hup; /**< Received SIGHUP count. */
40 /** Event generator for SIGHUP. */
41 static struct Signal sig_hup;
42 /** Event generator for SIGINT. */
43 static struct Signal sig_int;
44 /** Event generator for SIGTERM. */
45 static struct Signal sig_term;
47 /** Signal handler for SIGALRM.
48 * @param[in] sig Signal number (ignored).
50 static void sigalrm_handler(int sig)
55 /** Signal callback for SIGTERM.
56 * @param[in] ev Signal event descriptor.
58 static void sigterm_callback(struct Event* ev)
60 assert(0 != ev_signal(ev));
61 assert(ET_SIGNAL == ev_type(ev));
62 assert(SIGTERM == sig_signal(ev_signal(ev)));
63 assert(SIGTERM == ev_data(ev));
65 server_die("received signal SIGTERM");
68 /** Signal callback for SIGHUP.
69 * @param[in] ev Signal event descriptor.
71 static void sighup_callback(struct Event* ev)
73 assert(0 != ev_signal(ev));
74 assert(ET_SIGNAL == ev_type(ev));
75 assert(SIGHUP == sig_signal(ev_signal(ev)));
76 assert(SIGHUP == ev_data(ev));
82 /** Signal callback for SIGINT.
83 * @param[in] ev Signal event descriptor.
85 static void sigint_callback(struct Event* ev)
87 assert(0 != ev_signal(ev));
88 assert(ET_SIGNAL == ev_type(ev));
89 assert(SIGINT == sig_signal(ev_signal(ev)));
90 assert(SIGINT == ev_data(ev));
92 server_restart("caught signal: SIGINT");
95 /** Register all necessary signal handlers. */
96 void setup_signals(void)
100 act.sa_handler = SIG_IGN;
102 sigemptyset(&act.sa_mask);
103 sigaddset(&act.sa_mask, SIGPIPE);
104 sigaddset(&act.sa_mask, SIGALRM);
106 sigaddset(&act.sa_mask, SIGWINCH);
107 sigaction(SIGWINCH, &act, 0);
109 sigaction(SIGPIPE, &act, 0);
111 act.sa_handler = sigalrm_handler;
112 sigaction(SIGALRM, &act, 0);
114 signal_add(&sig_hup, sighup_callback, 0, SIGHUP);
115 signal_add(&sig_int, sigint_callback, 0, SIGINT);
116 signal_add(&sig_term, sigterm_callback, 0, SIGTERM);
118 #ifdef HAVE_RESTARTABLE_SYSCALLS
120 * At least on Apollo sr10.1 it seems continuing system calls
121 * after signal is the default. The following 'siginterrupt'
122 * should change that default to interrupting calls.
124 siginterrupt(SIGALRM, 1);