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.
25 #include "ircd_events.h"
26 #include "ircd_signal.h"
32 static struct tag_SignalCounter {
37 static struct Signal sig_hup;
38 static struct Signal sig_int;
39 static struct Signal sig_term;
41 static void sigalrm_handler(int sig)
46 static void sigterm_callback(struct Event* ev)
48 assert(0 != ev_signal(ev));
49 assert(ET_SIGNAL == ev_type(ev));
50 assert(SIGTERM == sig_signal(ev_signal(ev)));
51 assert(SIGTERM == ev_data(ev));
53 server_die("received signal SIGTERM");
56 static void sighup_callback(struct Event* ev)
58 assert(0 != ev_signal(ev));
59 assert(ET_SIGNAL == ev_type(ev));
60 assert(SIGHUP == sig_signal(ev_signal(ev)));
61 assert(SIGHUP == ev_data(ev));
67 static void sigint_callback(struct Event* ev)
69 assert(0 != ev_signal(ev));
70 assert(ET_SIGNAL == ev_type(ev));
71 assert(SIGINT == sig_signal(ev_signal(ev)));
72 assert(SIGINT == ev_data(ev));
74 server_restart("caught signal: SIGINT");
77 void setup_signals(void)
81 act.sa_handler = SIG_IGN;
83 sigemptyset(&act.sa_mask);
84 sigaddset(&act.sa_mask, SIGPIPE);
85 sigaddset(&act.sa_mask, SIGALRM);
87 sigaddset(&act.sa_mask, SIGWINCH);
88 sigaction(SIGWINCH, &act, 0);
90 sigaction(SIGPIPE, &act, 0);
92 act.sa_handler = sigalrm_handler;
93 sigaction(SIGALRM, &act, 0);
95 signal_add(&sig_hup, sighup_callback, 0, SIGHUP);
96 signal_add(&sig_int, sigint_callback, 0, SIGINT);
97 signal_add(&sig_term, sigterm_callback, 0, SIGTERM);
99 #ifdef HAVE_RESTARTABLE_SYSCALLS
101 * At least on Apollo sr10.1 it seems continuing system calls
102 * after signal is the default. The following 'siginterrupt'
103 * should change that default to interrupting calls.
105 siginterrupt(SIGALRM, 1);