SignalHandlers.cxx 1.86 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2011 The Music Player Daemon Project
3
 * http://www.musicpd.org
Warren Dukes's avatar
Warren Dukes committed
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17
 *
 * 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.
Warren Dukes's avatar
Warren Dukes committed
18 19
 */

20
#include "config.h"
21
#include "SignalHandlers.hxx"
22
#include "event/SignalMonitor.hxx"
23 24 25

#ifndef WIN32

26
#include "Log.hxx"
Max Kellermann's avatar
Max Kellermann committed
27
#include "Main.hxx"
28
#include "event/Loop.hxx"
29
#include "GlobalEvents.hxx"
30
#include "system/FatalError.hxx"
31 32

#include <glib.h>
33

34
#include <signal.h>
35

36
static EventLoop *shutdown_loop;
37

38 39
static void
HandleShutdownSignal()
40
{
41
	shutdown_loop->Break();
42 43
}

44 45 46 47
static void
x_sigaction(int signum, const struct sigaction *act)
{
	if (sigaction(signum, act, NULL) < 0)
48
		FatalSystemError("sigaction() failed");
49 50
}

51 52
static void
handle_reload_event(void)
53
{
54
	g_debug("got SIGHUP, reopening log files");
55
	cycle_log_files();
56 57
}

58 59
#endif

60 61
void
SignalHandlersInit(EventLoop &loop)
Avuton Olrich's avatar
Avuton Olrich committed
62
{
63 64
	SignalMonitorInit(loop);

65
#ifndef WIN32
Warren Dukes's avatar
Warren Dukes committed
66 67 68
	struct sigaction sa;

	sa.sa_flags = 0;
69
	sigemptyset(&sa.sa_mask);
Warren Dukes's avatar
Warren Dukes committed
70
	sa.sa_handler = SIG_IGN;
71
	x_sigaction(SIGPIPE, &sa);
72

73 74 75
	shutdown_loop = &loop;
	SignalMonitorRegister(SIGINT, HandleShutdownSignal);
	SignalMonitorRegister(SIGTERM, HandleShutdownSignal);
76

77
	SignalMonitorRegister(SIGHUP, handle_reload_event);
78
#endif
Warren Dukes's avatar
Warren Dukes committed
79
}
80 81 82 83 84 85

void
SignalHandlersFinish()
{
	SignalMonitorFinish();
}