2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-02-24 00:41:20 +01:00
|
|
|
*
|
|
|
|
* 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 2 of the License, 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-02-24 00:41:20 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-09 22:33:06 +01:00
|
|
|
#include "SignalHandlers.hxx"
|
2013-08-06 21:31:59 +02:00
|
|
|
#include "event/SignalMonitor.hxx"
|
2009-01-03 12:29:42 +01:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
|
2013-01-09 22:33:06 +01:00
|
|
|
#include "Log.hxx"
|
2012-09-28 00:40:00 +02:00
|
|
|
#include "Main.hxx"
|
2013-01-10 19:13:00 +01:00
|
|
|
#include "event/Loop.hxx"
|
2013-01-09 23:12:53 +01:00
|
|
|
#include "GlobalEvents.hxx"
|
2013-08-07 10:31:31 +02:00
|
|
|
#include "system/FatalError.hxx"
|
2008-12-30 19:50:38 +01:00
|
|
|
|
|
|
|
#include <glib.h>
|
2005-11-16 15:43:04 +01:00
|
|
|
|
2009-03-15 17:32:30 +01:00
|
|
|
#include <signal.h>
|
2008-10-08 10:49:29 +02:00
|
|
|
|
2013-08-06 21:31:59 +02:00
|
|
|
static EventLoop *shutdown_loop;
|
2004-04-12 01:07:43 +02:00
|
|
|
|
2013-08-06 21:31:59 +02:00
|
|
|
static void
|
|
|
|
HandleShutdownSignal()
|
2009-01-01 18:51:17 +01:00
|
|
|
{
|
2013-08-06 21:31:59 +02:00
|
|
|
shutdown_loop->Break();
|
2009-01-01 18:51:17 +01:00
|
|
|
}
|
|
|
|
|
2008-12-30 19:50:38 +01:00
|
|
|
static void
|
|
|
|
x_sigaction(int signum, const struct sigaction *act)
|
|
|
|
{
|
|
|
|
if (sigaction(signum, act, NULL) < 0)
|
2013-08-07 09:35:30 +02:00
|
|
|
FatalSystemError("sigaction() failed");
|
2008-12-30 19:50:38 +01:00
|
|
|
}
|
|
|
|
|
2009-01-01 18:51:17 +01:00
|
|
|
static void
|
|
|
|
handle_reload_event(void)
|
2008-12-30 19:50:38 +01:00
|
|
|
{
|
2009-03-15 18:23:00 +01:00
|
|
|
g_debug("got SIGHUP, reopening log files");
|
2009-01-01 18:51:17 +01:00
|
|
|
cycle_log_files();
|
2004-04-11 02:52:05 +02:00
|
|
|
}
|
|
|
|
|
2009-01-03 12:29:42 +01:00
|
|
|
#endif
|
|
|
|
|
2013-08-06 21:31:59 +02:00
|
|
|
void
|
|
|
|
SignalHandlersInit(EventLoop &loop)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2013-08-06 21:31:59 +02:00
|
|
|
SignalMonitorInit(loop);
|
|
|
|
|
2009-01-03 12:29:42 +01:00
|
|
|
#ifndef WIN32
|
2004-02-24 00:41:20 +01:00
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
sa.sa_flags = 0;
|
2006-07-19 01:38:21 +02:00
|
|
|
sigemptyset(&sa.sa_mask);
|
2004-02-24 00:41:20 +01:00
|
|
|
sa.sa_handler = SIG_IGN;
|
2010-07-25 11:09:13 +02:00
|
|
|
x_sigaction(SIGPIPE, &sa);
|
2008-12-30 19:50:38 +01:00
|
|
|
|
2013-08-06 21:31:59 +02:00
|
|
|
shutdown_loop = &loop;
|
|
|
|
SignalMonitorRegister(SIGINT, HandleShutdownSignal);
|
|
|
|
SignalMonitorRegister(SIGTERM, HandleShutdownSignal);
|
2008-12-30 19:50:38 +01:00
|
|
|
|
2013-08-06 21:31:59 +02:00
|
|
|
SignalMonitorRegister(SIGHUP, handle_reload_event);
|
2009-01-03 12:29:42 +01:00
|
|
|
#endif
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2013-08-06 21:31:59 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SignalHandlersFinish()
|
|
|
|
{
|
|
|
|
SignalMonitorFinish();
|
|
|
|
}
|