]> granicus.if.org Git - pdns/commitdiff
rec: Allow the SNMP thread to retrieve statistics
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 6 Jun 2018 14:05:20 +0000 (16:05 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 15 Jun 2018 12:28:42 +0000 (14:28 +0200)
pdns/pdns_recursor.cc

index 3c6a9b18906b9e6cfce976b72420adf4c59c3be7..41700632e59b2dfe39b1fd884bed756982e0e21e 100644 (file)
 typedef map<ComboAddress, uint32_t, ComboAddress::addressOnlyLessThan> tcpClientCounts_t;
 
 static thread_local std::shared_ptr<RecursorLua4> t_pdl;
-static thread_local int t_id;
+static thread_local int t_id = -1;
 static thread_local std::shared_ptr<Regex> t_traceRegex;
 static thread_local std::unique_ptr<tcpClientCounts_t> t_tcpClientCounts;
 #ifdef HAVE_PROTOBUF
@@ -2475,18 +2475,17 @@ struct ThreadMSG
 
 void broadcastFunction(const pipefunc_t& func)
 {
-  /* This function might be called by the worker with t_id 0 during startup
-     for the initialization of ACLs and domain maps */
-  if (t_id != s_handlerThreadID && t_id != s_distributorThreadID) {
+  /* This function might be called before t_id are set during startup
+     for the initialization of ACLs and domain maps, but the default is the same
+     than the handler thread */
+  if (t_id != s_handlerThreadID) {
     g_log<<Logger::Error<<"broadcastFunction() has been called by a worker ("<<t_id<<")"<<endl;
     exit(1);
   }
 
-  if (t_id == s_handlerThreadID) {
-    /* the distributor will call itself below, but if we are the handler thread,
-       call the function ourselves to update the ACL or domain maps for example */
-    func();
-  }
+  /* the distributor will call itself below, but if we are the handler thread,
+     call the function ourselves to update the ACL or domain maps for example */
+  func();
 
   int n = 0;
   for(ThreadPipeSet& tps : g_pipes)
@@ -2610,11 +2609,13 @@ vector<pair<DNSName, uint16_t> >& operator+=(vector<pair<DNSName, uint16_t> >&a,
 
 /*
   This function should only be called by the handler to gather metrics, wipe the cache,
-  reload the Lua script (not the Lua config) or change the current trace regex */
+  reload the Lua script (not the Lua config) or change the current trace regex,
+  and by the SNMP thread to gather metrics. */
 template<class T> T broadcastAccFunction(const boost::function<T*()>& func)
 {
+  /* the SNMP thread uses id -1 too */
   if (t_id != s_handlerThreadID) {
-    g_log<<Logger::Error<<"broadcastFunction has been called by a worker ("<<t_id<<")"<<endl;
+    g_log<<Logger::Error<<"broadcastAccFunction has been called by a worker ("<<t_id<<")"<<endl;
     exit(1);
   }