]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
make LUA state reuse optional 7869/head
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 3 Jun 2019 20:52:49 +0000 (22:52 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 4 Jun 2019 12:43:30 +0000 (14:43 +0200)
pdns/common_startup.cc
pdns/common_startup.hh
pdns/lua-record.cc

index bd57fc54235208771682b01da17d0c3a1d5e146d..1d1e51fea197e9d1f76e96a2bd96291b8d7faf6b 100644 (file)
@@ -511,6 +511,7 @@ void mainthread()
    g_8bitDNS = ::arg().mustDo("8bit-dns");
 #ifdef HAVE_LUA_RECORDS
    g_doLuaRecord = ::arg().mustDo("enable-lua-records");
+   g_LuaRecordSharedState = (::arg()["enable-lua-records"] == "shared");
    g_luaRecordExecLimit = ::arg().asNum("lua-records-exec-limit");
 #endif
 
index 1e1290ed57f30456169f8f473d8b808ea4834f1a..b57b4bcd5f8ad11c1e7d4b24a462b07d74cbed60 100644 (file)
@@ -57,6 +57,7 @@ extern bool g_anyToTcp;
 extern bool g_8bitDNS;
 #ifdef HAVE_LUA_RECORDS
 extern bool g_doLuaRecord;
+extern bool g_LuaRecordSharedState;
 #endif // HAVE_LUA_RECORDS
 
 #endif // COMMON_STARTUP_HH
index 3d757415fedd6cf9f6508174f86782a4c48807b5..0e2b9102b813e491bca4297308dd6cebed8dfd6e 100644 (file)
@@ -465,19 +465,19 @@ static vector<pair<int, ComboAddress> > convWIplist(std::unordered_map<int, wipl
   return ret;
 }
 
-thread_local unique_ptr<AuthLua4> alua;
+static thread_local unique_ptr<AuthLua4> s_LUA;
+bool g_LuaRecordSharedState;
 
 std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype)
 {
-  if(!alua) {
-    cerr<<"initializing AuthLua4"<<endl;
-
-    alua = make_unique<AuthLua4>();
+  if(!s_LUA ||                  // we don't have a Lua state yet
+     !g_LuaRecordSharedState) { // or we want a new one even if we had one
+    s_LUA = make_unique<AuthLua4>();
   }
 
   std::vector<shared_ptr<DNSRecordContent>> ret;
 
-  LuaContext& lua = *alua->getLua();
+  LuaContext& lua = *s_LUA->getLua();
   lua.writeVariable("qname", query);
   lua.writeVariable("who", dnsp.getRemote());
   lua.writeVariable("dh", (dnsheader*)&dnsp.d);