From 2168188114afee99e892d0c560a216076286488c Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 16 Nov 2016 15:37:04 +0100 Subject: [PATCH] rec: Wait until after daemonizing to start the RPZ and protobuf threads Otherwise they are killed when we call `fork()`. We still want to actually parse the configuration to check for syntax errors before daemonizing to be able to report any error, so when `daemon` is set to `yes`, we parse the Lua configuration early without starting any threads, and then again, starting the threads that time, after daemonizing. (cherry picked from commit a4241908a1c80c4293cfcd5056bb67138958f0e6) --- pdns/pdns_recursor.cc | 3 ++- pdns/rec-lua-conf.cc | 26 +++++++++++++++----------- pdns/rec-lua-conf.hh | 2 +- pdns/rec_channel_rec.cc | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 2b6c91f90..1ad2e1bff 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2606,7 +2606,7 @@ int serviceMain(int argc, char*argv[]) exit(99); } - loadRecursorLuaConfig(::arg()["lua-config-file"]); + loadRecursorLuaConfig(::arg()["lua-config-file"], ::arg().mustDo("daemon")); parseACLs(); sortPublicSuffixList(); @@ -2715,6 +2715,7 @@ int serviceMain(int argc, char*argv[]) L<>>& options) { + Lua.writeFunction("rpzMaster", [&lci, checkOnly](const string& master_, const string& zone_, const boost::optional>>& options) { try { boost::optional defpol; TSIGTriplet tt; @@ -185,11 +184,13 @@ void loadRecursorLuaConfig(const std::string& fname) const size_t zoneIdx = lci.dfe.size(); lci.dfe.setPolicyName(zoneIdx, polName); - auto sr=loadRPZFromServer(master, zone, lci.dfe, defpol, zoneIdx, tt, maxReceivedXFRMBytes * 1024 * 1024, localAddress); - if(refresh) - sr->d_st.refresh=refresh; - std::thread t(RPZIXFRTracker, master, zone, defpol, zoneIdx, tt, sr, maxReceivedXFRMBytes * 1024 * 1024, localAddress); - t.detach(); + if (!checkOnly) { + auto sr=loadRPZFromServer(master, zone, lci.dfe, defpol, zoneIdx, tt, maxReceivedXFRMBytes * 1024 * 1024, localAddress); + if(refresh) + sr->d_st.refresh=refresh; + std::thread t(RPZIXFRTracker, master, zone, defpol, zoneIdx, tt, sr, maxReceivedXFRMBytes * 1024 * 1024, localAddress); + t.detach(); + } } catch(std::exception& e) { theL()< timeout, const boost::optional maxQueuedEntries, const boost::optional reconnectWaitTime, const boost::optional maskV4, boost::optional maskV6, boost::optional asyncConnect) { + Lua.writeFunction("protobufServer", [&lci, checkOnly](const string& server_, const boost::optional timeout, const boost::optional maxQueuedEntries, const boost::optional reconnectWaitTime, const boost::optional maskV4, boost::optional maskV6, boost::optional asyncConnect) { try { ComboAddress server(server_); if (!lci.protobufServer) { - lci.protobufServer = std::make_shared(server, timeout ? *timeout : 2, maxQueuedEntries ? *maxQueuedEntries : 100, reconnectWaitTime ? *reconnectWaitTime : 1, asyncConnect ? *asyncConnect : false); + if (!checkOnly) { + lci.protobufServer = std::make_shared(server, timeout ? *timeout : 2, maxQueuedEntries ? *maxQueuedEntries : 100, reconnectWaitTime ? *reconnectWaitTime : 1, asyncConnect ? *asyncConnect : false); + } + if (maskV4) { lci.protobufMaskV4 = *maskV4; } diff --git a/pdns/rec-lua-conf.hh b/pdns/rec-lua-conf.hh index f3f598fab..07c3d7577 100644 --- a/pdns/rec-lua-conf.hh +++ b/pdns/rec-lua-conf.hh @@ -40,5 +40,5 @@ public: }; extern GlobalStateHolder g_luaconfs; -void loadRecursorLuaConfig(const std::string& fname); +void loadRecursorLuaConfig(const std::string& fname, bool checkOnly); diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index be3724b6b..f603d8680 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -1211,7 +1211,7 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP ::arg().set("lua-config-file") = *begin; try { - loadRecursorLuaConfig(::arg()["lua-config-file"]); + loadRecursorLuaConfig(::arg()["lua-config-file"], false); L<