2023-03-06 14:42:04 +01:00
|
|
|
// 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"
|
|
|
|
|
2017-12-12 10:22:20 +01:00
|
|
|
#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
|
|
|
{
|
2016-06-20 10:25:28 +02:00
|
|
|
auto &loop = *(EventLoop *)ctx;
|
|
|
|
loop.Break();
|
2013-10-18 08:56:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ShutdownHandler::ShutdownHandler(EventLoop &loop)
|
|
|
|
{
|
|
|
|
SignalMonitorInit(loop);
|
|
|
|
|
2016-06-20 10:25:28 +02:00
|
|
|
SignalMonitorRegister(SIGINT, {&loop, HandleShutdownSignal});
|
|
|
|
SignalMonitorRegister(SIGTERM, {&loop, HandleShutdownSignal});
|
2013-10-18 08:56:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ShutdownHandler::~ShutdownHandler()
|
|
|
|
{
|
|
|
|
SignalMonitorFinish();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|