rec: Add `getRecursorThreadId()` to Lua, identifying the current thread
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 1 Dec 2016 14:58:01 +0000 (15:58 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 12 Dec 2016 09:06:35 +0000 (10:06 +0100)
(cherry picked from commit b401545341c7e4bd2d27940e95f9fe1af374479d)

docs/markdown/recursor/scripting.md
pdns/lua-recursor4.cc
pdns/lua-recursor4.hh
pdns/pdns_recursor.cc

index 76550b945db766aeee87669e324a9afbe69333d2..f4030a8c7836e129a33d2a2b9f7ca664252d3222 100644 (file)
@@ -379,6 +379,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 2b6c91f90813bd908ebfee9cb9f1e86636bdd44e..23d13ce8aac69fa9b347bc5976f62626895ff2c0 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);