]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Wait until after daemonizing to start the RPZ and protobuf threads 4691/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 16 Nov 2016 14:37:04 +0000 (15:37 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 16 Nov 2016 14:37:04 +0000 (15:37 +0100)
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.

pdns/pdns_recursor.cc
pdns/rec-lua-conf.cc
pdns/rec-lua-conf.hh
pdns/rec_channel_rec.cc

index 38cad4f557e338eb737cd85ef3c4b0d14a4ce77a..e89b1855b0506d93e7256d9eab9586cdc9ff645d 100644 (file)
@@ -2638,7 +2638,7 @@ int serviceMain(int argc, char*argv[])
 
   g_dnssecLogBogus = ::arg().mustDo("dnssec-log-bogus");
 
-  loadRecursorLuaConfig(::arg()["lua-config-file"]);
+  loadRecursorLuaConfig(::arg()["lua-config-file"], ::arg().mustDo("daemon"));
 
   parseACLs();
   sortPublicSuffixList();
@@ -2730,6 +2730,7 @@ int serviceMain(int argc, char*argv[])
     L<<Logger::Warning<<"Calling daemonize, going to background"<<endl;
     L.toConsole(Logger::Critical);
     daemonize();
+    loadRecursorLuaConfig(::arg()["lua-config-file"], false);
   }
   signal(SIGUSR1,usr1Handler);
   signal(SIGUSR2,usr2Handler);
index a499b8699bcefabd9bd1e8b8f6e21e13aad743c5..86050da3b0ac788d370cbf5cc298fff919dedfb3 100644 (file)
@@ -53,15 +53,14 @@ typename C::value_type::second_type constGet(const C& c, const std::string& name
 }
 
 #ifndef HAVE_LUA
-void loadRecursorLuaConfig(const std::string& fname)
+void loadRecursorLuaConfig(const std::string& fname, bool checkOnly)
 {
   if(!fname.empty())
     throw PDNSException("Asked to load a Lua configuration file '"+fname+"' in binary without Lua support");
 }
 #else
 
-
-void loadRecursorLuaConfig(const std::string& fname)
+void loadRecursorLuaConfig(const std::string& fname, bool checkOnly)
 {
   LuaConfigItems lci;
 
@@ -130,7 +129,7 @@ void loadRecursorLuaConfig(const std::string& fname)
     });
 
 
-  Lua.writeFunction("rpzMaster", [&lci](const string& master_, const string& zone_, const boost::optional<std::unordered_map<string,boost::variant<int, string>>>& options) {
+  Lua.writeFunction("rpzMaster", [&lci, checkOnly](const string& master_, const string& zone_, const boost::optional<std::unordered_map<string,boost::variant<int, string>>>& options) {
       try {
        boost::optional<DNSFilterEngine::Policy> defpol;
         TSIGTriplet tt;
@@ -186,11 +185,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()<<Logger::Error<<"Unable to load RPZ zone '"<<zone_<<"' from '"<<master_<<"': "<<e.what()<<endl;
@@ -265,11 +266,14 @@ void loadRecursorLuaConfig(const std::string& fname)
     });
 
 #if HAVE_PROTOBUF
-  Lua.writeFunction("protobufServer", [&lci](const string& server_, const boost::optional<uint16_t> timeout, const boost::optional<uint64_t> maxQueuedEntries, const boost::optional<uint8_t> reconnectWaitTime, const boost::optional<uint8_t> maskV4, boost::optional<uint8_t> maskV6, boost::optional<bool> asyncConnect, boost::optional<bool> taggedOnly) {
+  Lua.writeFunction("protobufServer", [&lci, checkOnly](const string& server_, const boost::optional<uint16_t> timeout, const boost::optional<uint64_t> maxQueuedEntries, const boost::optional<uint8_t> reconnectWaitTime, const boost::optional<uint8_t> maskV4, boost::optional<uint8_t> maskV6, boost::optional<bool> asyncConnect, boost::optional<bool> taggedOnly) {
       try {
        ComboAddress server(server_);
         if (!lci.protobufServer) {
-          lci.protobufServer = std::make_shared<RemoteLogger>(server, timeout ? *timeout : 2, maxQueuedEntries ? *maxQueuedEntries : 100, reconnectWaitTime ? *reconnectWaitTime : 1, asyncConnect ? *asyncConnect : false);
+          if (!checkOnly) {
+            lci.protobufServer = std::make_shared<RemoteLogger>(server, timeout ? *timeout : 2, maxQueuedEntries ? *maxQueuedEntries : 100, reconnectWaitTime ? *reconnectWaitTime : 1, asyncConnect ? *asyncConnect : false);
+          }
+
           if (maskV4) {
             lci.protobufMaskV4 = *maskV4;
           }
index 85224663e043b46f181bcf24defc6a904d026452..a96e5b882af7ba75ec54933634d2bb360a97387b 100644 (file)
@@ -41,5 +41,5 @@ public:
 };
 
 extern GlobalStateHolder<LuaConfigItems> g_luaconfs;
-void loadRecursorLuaConfig(const std::string& fname);
+void loadRecursorLuaConfig(const std::string& fname, bool checkOnly);
 
index 9d029d34ec6e6371ed5893d998158e348e145417..f2c197094d5b18abb1a22503621945e43d3ffb2c 100644 (file)
@@ -1234,7 +1234,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<<Logger::Warning<<"Reloaded Lua configuration file '"<<::arg()["lua-config-file"]<<"', requested via control channel"<<endl;
       return "Reloaded Lua configuration file '"+::arg()["lua-config-file"]+"'\n";
     }