2007-01-25 07:40:21 +01:00
|
|
|
/************************************************************************
|
|
|
|
* IRC - Internet Relay Chat, src/ircd_signal.c
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and
|
|
|
|
* University of Oulu, Computing Center
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 1, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "ircd_signal.h"
|
|
|
|
#include "ircd.h" /* dorehash */
|
|
|
|
#include "restart.h" /* server_reboot */
|
2008-04-03 04:52:01 +02:00
|
|
|
#include "logger.h"
|
2007-01-25 07:40:21 +01:00
|
|
|
#include "s_conf.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "send.h"
|
|
|
|
|
2016-03-20 08:00:22 +01:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2016-03-20 12:22:39 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* dummy_handler - don't know if this is really needed but if alarm is still
|
|
|
|
* being used we probably will
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dummy_handler(int sig)
|
|
|
|
{
|
|
|
|
/* Empty */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
sigchld_handler(int sig)
|
|
|
|
{
|
2008-04-18 01:01:38 +02:00
|
|
|
int status, olderrno;
|
|
|
|
|
|
|
|
olderrno = errno;
|
|
|
|
while (waitpid(-1, &status, WNOHANG) > 0)
|
|
|
|
;
|
|
|
|
errno = olderrno;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2008-04-18 01:01:38 +02:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* sigterm_handler - exit the server
|
|
|
|
*/
|
2016-06-01 22:11:46 +02:00
|
|
|
static void
|
|
|
|
sigterm_handler(int sig) __attribute__((noreturn));
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
static void
|
|
|
|
sigterm_handler(int sig)
|
|
|
|
{
|
2008-04-20 05:38:56 +02:00
|
|
|
ircd_shutdown("Received SIGTERM");
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2014-03-03 05:25:47 +01:00
|
|
|
/*
|
2007-01-25 07:40:21 +01:00
|
|
|
* sighup_handler - reread the server configuration
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sighup_handler(int sig)
|
|
|
|
{
|
2016-03-09 09:06:21 +01:00
|
|
|
dorehash = true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sigusr1_handler - reread the motd file
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sigusr1_handler(int sig)
|
|
|
|
{
|
2016-03-09 09:06:21 +01:00
|
|
|
doremotd = true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sigusr2_handler(int sig)
|
|
|
|
{
|
2016-03-09 09:06:21 +01:00
|
|
|
dorehashbans = true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sigint_handler - restart the server
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sigint_handler(int sig)
|
|
|
|
{
|
2016-03-09 09:06:21 +01:00
|
|
|
static bool restarting = false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(server_state_foreground)
|
|
|
|
{
|
|
|
|
ilog(L_MAIN, "Server exiting on SIGINT");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ilog(L_MAIN, "Server Restarting on SIGINT");
|
2016-03-09 09:06:21 +01:00
|
|
|
if(!restarting)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-09 09:06:21 +01:00
|
|
|
restarting = true;
|
2007-01-25 07:40:21 +01:00
|
|
|
server_reboot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* setup_signals - initialize signal handlers for server
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
setup_signals()
|
|
|
|
{
|
2011-08-31 01:04:04 +02:00
|
|
|
sigset_t sigs;
|
2007-01-25 07:40:21 +01:00
|
|
|
struct sigaction act;
|
|
|
|
|
2011-08-31 01:04:04 +02:00
|
|
|
sigemptyset(&sigs);
|
2007-01-25 07:40:21 +01:00
|
|
|
act.sa_flags = 0;
|
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
sigaddset(&act.sa_mask, SIGPIPE);
|
|
|
|
sigaddset(&act.sa_mask, SIGALRM);
|
|
|
|
#ifdef SIGTRAP
|
|
|
|
sigaddset(&act.sa_mask, SIGTRAP);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
# ifdef SIGWINCH
|
|
|
|
sigaddset(&act.sa_mask, SIGWINCH);
|
|
|
|
sigaction(SIGWINCH, &act, 0);
|
|
|
|
# endif
|
|
|
|
sigaction(SIGPIPE, &act, 0);
|
|
|
|
#ifdef SIGTRAP
|
|
|
|
sigaction(SIGTRAP, &act, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
act.sa_handler = dummy_handler;
|
|
|
|
sigaction(SIGALRM, &act, 0);
|
2011-08-31 01:04:04 +02:00
|
|
|
sigaddset(&sigs, SIGALRM);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
act.sa_handler = sighup_handler;
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
sigaddset(&act.sa_mask, SIGHUP);
|
|
|
|
sigaction(SIGHUP, &act, 0);
|
2011-08-31 01:04:04 +02:00
|
|
|
sigaddset(&sigs, SIGHUP);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
act.sa_handler = sigint_handler;
|
|
|
|
sigaddset(&act.sa_mask, SIGINT);
|
|
|
|
sigaction(SIGINT, &act, 0);
|
2011-08-31 01:04:04 +02:00
|
|
|
sigaddset(&sigs, SIGINT);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
act.sa_handler = sigterm_handler;
|
|
|
|
sigaddset(&act.sa_mask, SIGTERM);
|
|
|
|
sigaction(SIGTERM, &act, 0);
|
2011-08-31 01:04:04 +02:00
|
|
|
sigaddset(&sigs, SIGTERM);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
act.sa_handler = sigusr1_handler;
|
|
|
|
sigaddset(&act.sa_mask, SIGUSR1);
|
|
|
|
sigaction(SIGUSR1, &act, 0);
|
2011-08-31 01:04:04 +02:00
|
|
|
sigaddset(&sigs, SIGUSR1);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
act.sa_handler = sigusr2_handler;
|
|
|
|
sigaddset(&act.sa_mask, SIGUSR2);
|
|
|
|
sigaction(SIGUSR2, &act, 0);
|
2011-08-31 01:04:04 +02:00
|
|
|
sigaddset(&sigs, SIGUSR2);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
act.sa_handler = sigchld_handler;
|
|
|
|
sigaddset(&act.sa_mask, SIGCHLD);
|
|
|
|
sigaction(SIGCHLD, &act, 0);
|
2011-08-31 01:04:04 +02:00
|
|
|
sigaddset(&sigs, SIGCHLD);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2011-08-31 01:04:04 +02:00
|
|
|
sigprocmask(SIG_UNBLOCK, &sigs, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-03-20 08:00:22 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
setup_signals()
|
|
|
|
{
|
|
|
|
/* this is a stub for mingw32 */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setup_reboot_signals()
|
|
|
|
{
|
|
|
|
/* this is a stub for mingw32 */
|
|
|
|
}
|
|
|
|
#endif
|