Permalink
Browse files

rec: Add `getRecursorThreadId()` to Lua, identifying the current thread

(cherry picked from commit b401545)
  • Loading branch information...
1 parent 1dde8cc commit bb6bd6e401caabdfa2834a40e960eb8a0076548c @rgacogne rgacogne committed Dec 1, 2016
Showing with 14 additions and 2 deletions.
  1. +3 −0 docs/markdown/recursor/scripting.md
  2. +5 −1 pdns/lua-recursor4.cc
  3. +1 −0 pdns/lua-recursor4.hh
  4. +5 −1 pdns/pdns_recursor.cc
@@ -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
@@ -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) {
@@ -31,6 +31,7 @@
#endif
string GenUDPQueryResponse(const ComboAddress& dest, const string& query);
+unsigned int getRecursorThreadId();
class LuaContext;
@@ -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);

0 comments on commit bb6bd6e

Please sign in to comment.