unix/SignalHandlers: shut down if parent process dies in --no-daemon mode
By default, if the parent of a process dies, the process gets SIGHUP and is supposed to shut down. This however doesn't work for MPD, because MPD redefines SIGHUP with a different meaning (like most daemons do). To work around this, we configure the kernel to send SIGTERM instead of SIGHUP. Closes https://github.com/MusicPlayerDaemon/MPD/issues/1706
This commit is contained in:
parent
d9952b9054
commit
c83ab0dc58
2
NEWS
2
NEWS
|
@ -29,6 +29,8 @@ ver 0.24 (not yet released)
|
|||
* switch to C++20
|
||||
- GCC 10 or clang 11 (or newer) recommended
|
||||
* static partition configuration
|
||||
* Linux
|
||||
- shut down if parent process dies in --no-daemon mode
|
||||
* Windows
|
||||
- build with libsamplerate
|
||||
- remove JACK DLL support
|
||||
|
|
|
@ -431,7 +431,10 @@ MainConfigured(const CommandLineOptions &options,
|
|||
#ifndef ANDROID
|
||||
setup_log_output();
|
||||
|
||||
const ScopeSignalHandlersInit signal_handlers_init(instance);
|
||||
const ScopeSignalHandlersInit signal_handlers_init{
|
||||
instance,
|
||||
options.daemon,
|
||||
};
|
||||
#endif
|
||||
|
||||
instance.io_thread.Start();
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
|
||||
#include <csignal>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/prctl.h>
|
||||
#endif
|
||||
|
||||
static constexpr Domain signal_handlers_domain("signal_handlers");
|
||||
|
||||
static void
|
||||
|
@ -60,7 +64,7 @@ handle_reload_event(void *ctx) noexcept
|
|||
#endif
|
||||
|
||||
void
|
||||
SignalHandlersInit(Instance &instance)
|
||||
SignalHandlersInit(Instance &instance, bool daemon)
|
||||
{
|
||||
auto &loop = instance.event_loop;
|
||||
|
||||
|
@ -79,6 +83,14 @@ SignalHandlersInit(Instance &instance)
|
|||
|
||||
SignalMonitorRegister(SIGHUP, {&instance, handle_reload_event});
|
||||
#endif
|
||||
|
||||
if (!daemon) {
|
||||
#ifdef __linux__
|
||||
/* if MPD was not daemonized, shut it down when the
|
||||
parent process dies */
|
||||
prctl(PR_SET_PDEATHSIG, SIGTERM);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -23,15 +23,15 @@
|
|||
struct Instance;
|
||||
|
||||
void
|
||||
SignalHandlersInit(Instance &instance);
|
||||
SignalHandlersInit(Instance &instance, bool daemon);
|
||||
|
||||
void
|
||||
SignalHandlersFinish() noexcept;
|
||||
|
||||
class ScopeSignalHandlersInit {
|
||||
public:
|
||||
ScopeSignalHandlersInit(Instance &instance) {
|
||||
SignalHandlersInit(instance);
|
||||
ScopeSignalHandlersInit(Instance &instance, bool daemon) {
|
||||
SignalHandlersInit(instance, daemon);
|
||||
}
|
||||
|
||||
~ScopeSignalHandlersInit() noexcept {
|
||||
|
|
Loading…
Reference in New Issue