From 055d1cecd1b61be9e50e9a0e590e7e12ac911aed Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Fri, 24 Jun 2022 13:02:07 +0200 Subject: [PATCH] dnsdist newThread(): mask SIGTERM --- pdns/dnsdist-lua.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 157e34e37a..ec50b3b4b1 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -270,6 +270,15 @@ void checkParameterBound(const std::string& parameter, uint64_t value, size_t ma static void LuaThread(const std::string code) { LuaContext l; + + // mask SIGTERM on threads so the signal always comes to dnsdist itself + sigset_t blockSignals; + + sigemptyset(&blockSignals); + sigaddset(&blockSignals, SIGTERM); + + pthread_sigmask(SIG_BLOCK, &blockSignals, nullptr); + // submitToMainThread is camelcased, threadmessage is not. // This follows our tradition of hooks we call being lowercased but functions the user can call being camelcased. l.writeFunction("submitToMainThread", [](std::string cmd, LuaAssociativeTable data) { @@ -2873,6 +2882,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) return; } std::thread newThread(LuaThread, code); + newThread.detach(); }); -- 2.47.2