]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Add `getRecursorThreadId()` to Lua, identifying the current thread 4724/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 1 Dec 2016 14:58:01 +0000 (15:58 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Sun, 4 Dec 2016 20:36:43 +0000 (21:36 +0100)
docs/markdown/recursor/scripting.md
pdns/lua-recursor4.cc
pdns/lua-recursor4.hh
pdns/pdns_recursor.cc

index eebb53cf1b74b20714f83ee5d1320f3c71918e23..2beb7c75842a692b2c3d471f60b14aa781498298 100644 (file)
@@ -383,6 +383,9 @@ entry.  Entries are listed in the following table:
 Public Suffix List. In general it will tell you the 'registered domain' for a given
 name.
 
+`getRecursorThreadId()` returns an unsigned integer identifying the thread
+handling the current request.
+
 ## DNS64
 The `getFakeAAAARecords` and `getFakePTRRecords` followupFunctions can be used
 to implement DNS64. See [DNS64 support in the PowerDNS Recursor](dns64.md) for
index faf5bef06afdf398f3215b2b4874e65989ae78cc..ea0cde2bf3bfd93b86dbd3a9f56a7780a26d3955 100644 (file)
@@ -531,7 +531,11 @@ RecursorLua4::RecursorLua4(const std::string& fname)
   d_lw->registerFunction("incBy", &DynMetric::incBy);
   d_lw->registerFunction("set", &DynMetric::set);
   d_lw->registerFunction("get", &DynMetric::get);
-  
+
+  d_lw->writeFunction("getRecursorThreadId", []() {
+      return getRecursorThreadId();
+    });
+
   
   ifstream ifs(fname);
   if(!ifs) {
index a684ee0ae3563d73d9d4aced21672a31367a1673..4277b9721482b3b08af7d4caa8d2befe82e0dc35 100644 (file)
@@ -31,6 +31,7 @@
 #endif
 
 string GenUDPQueryResponse(const ComboAddress& dest, const string& query);
+unsigned int getRecursorThreadId();
 
 class LuaContext;
 
index e89b1855b0506d93e7256d9eab9586cdc9ff645d..4fe1f7433438e134644e457e522f249563d855dc 100644 (file)
@@ -91,7 +91,7 @@ extern SortList g_sortlist;
 #endif
 
 __thread FDMultiplexer* t_fdm;
-__thread unsigned int t_id;
+static __thread unsigned int t_id;
 unsigned int g_maxTCPPerClient;
 unsigned int g_networkTimeoutMsec;
 uint64_t g_latencyStatSize;
@@ -214,6 +214,10 @@ ArgvMap &arg()
   return theArg;
 }
 
+unsigned int getRecursorThreadId()
+{
+  return t_id;
+}
 
 void handleTCPClientWritable(int fd, FDMultiplexer::funcparam_t& var);