mpd/test/ShutdownHandler.cxx

33 lines
608 B
C++
Raw Permalink Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
2013-10-18 08:56:25 +02:00
#include "ShutdownHandler.hxx"
#ifndef _WIN32
2013-10-18 08:56:25 +02:00
#include "event/SignalMonitor.hxx"
#include "event/Loop.hxx"
#include <signal.h>
static void
2020-10-13 17:25:53 +02:00
HandleShutdownSignal(void *ctx) noexcept
2013-10-18 08:56:25 +02:00
{
auto &loop = *(EventLoop *)ctx;
loop.Break();
2013-10-18 08:56:25 +02:00
}
ShutdownHandler::ShutdownHandler(EventLoop &loop)
{
SignalMonitorInit(loop);
SignalMonitorRegister(SIGINT, {&loop, HandleShutdownSignal});
SignalMonitorRegister(SIGTERM, {&loop, HandleShutdownSignal});
2013-10-18 08:56:25 +02:00
}
ShutdownHandler::~ShutdownHandler()
{
SignalMonitorFinish();
}
#endif