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"
|
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-09 22:37:47 +01:00
|
|
|
#include "EventPipe.hxx"
|
2010-09-25 15:00:43 +02:00
|
|
|
#include "mpd_error.h"
|
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
|
|
|
#include <errno.h>
|
2008-12-30 19:50:38 +01:00
|
|
|
#include <string.h>
|
2008-10-08 10:49:29 +02:00
|
|
|
|
2008-12-30 19:50:38 +01:00
|
|
|
static void exit_signal_handler(G_GNUC_UNUSED int signum)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-12-30 19:50:38 +01:00
|
|
|
g_main_loop_quit(main_loop);
|
|
|
|
}
|
2004-04-12 01:07:43 +02:00
|
|
|
|
2009-01-01 18:51:17 +01:00
|
|
|
static void reload_signal_handler(G_GNUC_UNUSED int signum)
|
|
|
|
{
|
|
|
|
event_pipe_emit_fast(PIPE_EVENT_RELOAD);
|
|
|
|
}
|
|
|
|
|
2008-12-30 19:50:38 +01:00
|
|
|
static void
|
|
|
|
x_sigaction(int signum, const struct sigaction *act)
|
|
|
|
{
|
|
|
|
if (sigaction(signum, act, NULL) < 0)
|
2010-09-25 15:00:43 +02:00
|
|
|
MPD_ERROR("sigaction() failed: %s", strerror(errno));
|
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
|
|
|
|
|
2006-08-08 04:23:21 +02:00
|
|
|
void initSigHandlers(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
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
|
|
|
|
|
|
|
sa.sa_handler = exit_signal_handler;
|
|
|
|
x_sigaction(SIGINT, &sa);
|
|
|
|
x_sigaction(SIGTERM, &sa);
|
|
|
|
|
2009-01-01 18:51:17 +01:00
|
|
|
event_pipe_register(PIPE_EVENT_RELOAD, handle_reload_event);
|
|
|
|
sa.sa_handler = reload_signal_handler;
|
|
|
|
x_sigaction(SIGHUP, &sa);
|
2009-01-03 12:29:42 +01:00
|
|
|
#endif
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|