| 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 |
|
|
#include "ircd_signal.h" |
| 27 |
|
|
#include "ircd.h" /* dorehash */ |
| 28 |
michael |
599 |
#include "restart.h" /* server_die */ |
| 29 |
adx |
30 |
|
| 30 |
|
|
/* |
| 31 |
adx |
78 |
* signal_handler - general handler for ircd signals |
| 32 |
adx |
30 |
*/ |
| 33 |
|
|
static void |
| 34 |
adx |
78 |
signal_handler(int sig) |
| 35 |
adx |
30 |
{ |
| 36 |
adx |
78 |
switch (sig) |
| 37 |
|
|
{ |
| 38 |
|
|
case SIG_DIE: |
| 39 |
|
|
server_die("received signal SIGTERM", NO); |
| 40 |
michael |
599 |
break; |
| 41 |
adx |
78 |
case SIG_RESTART: |
| 42 |
adx |
743 |
server_die("received signal SIGINT", !ServerState.foreground); |
| 43 |
michael |
599 |
break; |
| 44 |
adx |
78 |
case SIG_REHASH: |
| 45 |
|
|
dorehash = 1; |
| 46 |
|
|
break; |
| 47 |
|
|
case SIG_REMOTD: |
| 48 |
|
|
doremotd = 1; |
| 49 |
|
|
} |
| 50 |
adx |
30 |
} |
| 51 |
|
|
|
| 52 |
adx |
78 |
#ifndef _WIN32 |
| 53 |
adx |
30 |
/* |
| 54 |
|
|
* |
| 55 |
|
|
* inputs - nothing |
| 56 |
|
|
* output - nothing |
| 57 |
|
|
* side effects - Reaps zombies periodically |
| 58 |
|
|
* -AndroSyn |
| 59 |
|
|
*/ |
| 60 |
|
|
static void |
| 61 |
|
|
sigchld_handler(int sig) |
| 62 |
|
|
{ |
| 63 |
|
|
int status; |
| 64 |
|
|
waitpid(-1, &status, WNOHANG); |
| 65 |
|
|
} |
| 66 |
adx |
78 |
#endif |
| 67 |
adx |
30 |
|
| 68 |
|
|
/* |
| 69 |
|
|
* setup_signals - initialize signal handlers for server |
| 70 |
|
|
*/ |
| 71 |
|
|
void |
| 72 |
|
|
setup_signals(void) |
| 73 |
|
|
{ |
| 74 |
adx |
78 |
#ifdef _WIN32 |
| 75 |
|
|
dispatch_wm_signal = signal_handler; |
| 76 |
|
|
#else |
| 77 |
adx |
30 |
struct sigaction act; |
| 78 |
|
|
|
| 79 |
|
|
act.sa_flags = 0; |
| 80 |
|
|
act.sa_handler = SIG_IGN; |
| 81 |
michael |
599 |
|
| 82 |
adx |
30 |
sigemptyset(&act.sa_mask); |
| 83 |
michael |
599 |
|
| 84 |
adx |
30 |
sigaddset(&act.sa_mask, SIGPIPE); |
| 85 |
michael |
599 |
sigaction(SIGPIPE, &act, 0); |
| 86 |
|
|
|
| 87 |
adx |
30 |
sigaddset(&act.sa_mask, SIGALRM); |
| 88 |
michael |
600 |
sigaction(SIGALRM, &act, 0); |
| 89 |
|
|
|
| 90 |
adx |
30 |
#ifdef SIGWINCH |
| 91 |
|
|
sigaddset(&act.sa_mask, SIGWINCH); |
| 92 |
|
|
sigaction(SIGWINCH, &act, 0); |
| 93 |
|
|
#endif |
| 94 |
michael |
599 |
|
| 95 |
|
|
#ifdef SIGXFSZ |
| 96 |
|
|
sigaddset(&act.sa_mask, SIGXFSZ); |
| 97 |
|
|
sigaction(SIGXFSZ, &act, 0); |
| 98 |
adx |
30 |
#endif |
| 99 |
|
|
|
| 100 |
adx |
78 |
act.sa_handler = signal_handler; |
| 101 |
adx |
30 |
sigemptyset(&act.sa_mask); |
| 102 |
michael |
600 |
|
| 103 |
adx |
78 |
sigaddset(&act.sa_mask, SIG_REHASH); |
| 104 |
|
|
sigaction(SIG_REHASH, &act, 0); |
| 105 |
adx |
30 |
|
| 106 |
adx |
78 |
sigaddset(&act.sa_mask, SIG_RESTART); |
| 107 |
|
|
sigaction(SIG_RESTART, &act, 0); |
| 108 |
adx |
30 |
|
| 109 |
adx |
78 |
sigaddset(&act.sa_mask, SIG_DIE); |
| 110 |
|
|
sigaction(SIG_DIE, &act, 0); |
| 111 |
adx |
30 |
|
| 112 |
adx |
78 |
sigaddset(&act.sa_mask, SIG_REMOTD); |
| 113 |
|
|
sigaction(SIG_REMOTD, &act, 0); |
| 114 |
adx |
30 |
|
| 115 |
|
|
act.sa_handler = sigchld_handler; |
| 116 |
|
|
sigaddset(&act.sa_mask, SIGCHLD); |
| 117 |
|
|
sigaction(SIGCHLD, &act, 0); |
| 118 |
adx |
78 |
#endif |
| 119 |
adx |
30 |
} |