pdns-recursor: Name all threads
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 27 Sep 2018 07:10:02 +0000 (09:10 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Thu, 27 Sep 2018 07:57:07 +0000 (09:57 +0200)
pdns/nod.cc
pdns/pdns_recursor.cc
pdns/remote_logger.cc
pdns/rpzloader.cc
pdns/snmp-agent.cc
pdns/webserver.cc

index 287bd45f579ac6f6bfd644d73d6a1a60d2eb8f62..ef3c8a3d67d53ea1e2f1b325768daf2015ff3cd4 100644 (file)
@@ -99,6 +99,11 @@ bool NODDB::init(bool ignore_pid) {
 
 void NODDB::housekeepingThread()
 {
+  string threadName = "pdns-r/NOD-hk";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for NOD housekeeping thread: "<<strerror(retval)<<endl;
+  }
   for (;;) {
     sleep(d_snapshot_interval);
     {
index 9444cdb2f2ec5678d807379475702798865fd520..aeab8c5b69db91d47dcee82318607d4e636a6dbe 100644 (file)
@@ -30,6 +30,7 @@
 #include <boost/container/flat_set.hpp>
 #endif
 #include "ws-recursor.hh"
+#include <thread>
 #include <pthread.h>
 #include "recpacketcache.hh"
 #include "utility.hh"
@@ -3095,7 +3096,7 @@ static void checkOrFixFDS()
   }
 }
 
-static void* recursorThread(unsigned int tid);
+static void* recursorThread(unsigned int tid, const string& threadName);
 
 static void* pleaseSupplantACLs(std::shared_ptr<NetmaskGroup> ng)
 {
@@ -3680,14 +3681,14 @@ static int serviceMain(int argc, char*argv[])
     /* This thread handles the web server, carbon, statistics and the control channel */
     auto& handlerInfos = s_threadInfos.at(0);
     handlerInfos.isHandler = true;
-    handlerInfos.thread = std::thread(recursorThread, 0);
+    handlerInfos.thread = std::thread(recursorThread, 0, "main");
 
     setCPUMap(cpusMap, currentThreadId, pthread_self());
 
     auto& infos = s_threadInfos.at(currentThreadId);
     infos.isListener = true;
     infos.isWorker = true;
-    recursorThread(currentThreadId++);
+    recursorThread(currentThreadId++, "worker");
   }
   else {
 
@@ -3696,7 +3697,7 @@ static int serviceMain(int argc, char*argv[])
       for(unsigned int n=0; n < g_numDistributorThreads; ++n) {
         auto& infos = s_threadInfos.at(currentThreadId);
         infos.isListener = true;
-        infos.thread = std::thread(recursorThread, currentThreadId++);
+        infos.thread = std::thread(recursorThread, currentThreadId++, "distr");
 
         setCPUMap(cpusMap, currentThreadId, infos.thread.native_handle());
       }
@@ -3708,7 +3709,7 @@ static int serviceMain(int argc, char*argv[])
       auto& infos = s_threadInfos.at(currentThreadId);
       infos.isListener = g_weDistributeQueries ? false : true;
       infos.isWorker = true;
-      infos.thread = std::thread(recursorThread, currentThreadId++);
+      infos.thread = std::thread(recursorThread, currentThreadId++, "worker");
 
       setCPUMap(cpusMap, currentThreadId, infos.thread.native_handle());
     }
@@ -3720,18 +3721,26 @@ static int serviceMain(int argc, char*argv[])
     /* This thread handles the web server, carbon, statistics and the control channel */
     auto& infos = s_threadInfos.at(0);
     infos.isHandler = true;
-    infos.thread = std::thread(recursorThread, 0);
+    infos.thread = std::thread(recursorThread, 0, "web+stat");
 
     s_threadInfos.at(0).thread.join();
   }
   return 0;
 }
 
-static void* recursorThread(unsigned int n)
+static void* recursorThread(unsigned int n, const string& threadName)
 try
 {
   t_id=n;
   auto& threadInfo = s_threadInfos.at(t_id);
+
+  static string threadPrefix = "pdns-r/";
+
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>((threadPrefix + threadName).c_str()));
+  if (retval != 0) {
+    g_log<<Logger::Warning<<"Could not set thread name "<<threadPrefix<<threadName<<" for thread number "<<n<<": "<<strerror(retval)<<endl;
+  }
+
   SyncRes tmp(g_now); // make sure it allocates tsstorage before we do anything, like primeHints or so..
   SyncRes::setDomainMap(g_initialDomainMap);
   t_allowFrom = g_initialAllowFrom;
index 70b29f701bdee3f6f35793225f018b86d3270dba..c186e017a9a17c3e2604d3831a6a74190730080f 100644 (file)
@@ -1,4 +1,5 @@
 #include <unistd.h>
+#include <pthread.h>
 #include "remote_logger.hh"
 #include "config.h"
 #ifdef PDNS_CONFIG_ARGS
@@ -41,6 +42,11 @@ void RemoteLogger::busyReconnectLoop()
 
 void RemoteLogger::worker()
 {
+  string threadName = "pdns-r/remLog";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for Remote Logger thread: "<<strerror(retval)<<endl;
+  }
   while(true) {
     std::string data;
     {
index 6ecc9c3244c144b1f3679d06034e888bac5aba57..5e863dde504e2a187584e8ff3f56686f12db61b1 100644 (file)
@@ -1,3 +1,4 @@
+#include <pthread.h>
 #include "dnsparser.hh"
 #include "dnsrecords.hh"
 #include "ixfr.hh"
@@ -339,6 +340,12 @@ static bool dumpZoneToDisk(const DNSName& zoneName, const std::shared_ptr<DNSFil
 
 void RPZIXFRTracker(const std::vector<ComboAddress> masters, boost::optional<DNSFilterEngine::Policy> defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, const uint16_t axfrTimeout, std::shared_ptr<SOARecordContent> sr, std::string dumpZoneFileName, uint64_t configGeneration)
 {
+  string threadName = "pdns-r/RPZIXFR";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for RPZ IXFRTracker thread: "<<strerror(retval)<<endl;
+  }
+
   bool isPreloaded = sr != nullptr;
   auto luaconfsLocal = g_luaconfs.getLocal();
   /* we can _never_ modify this zone directly, we need to do a full copy then replace the existing zone */
index 3187a56d72033ec98c992235d97a9254f32d05d8..7277a05db2dd033ddaf88154a93340946ea34d5b 100644 (file)
@@ -1,5 +1,6 @@
 #include "snmp-agent.hh"
 #include "misc.hh"
+#include "logger.hh"
 
 #ifdef HAVE_NET_SNMP
 
@@ -100,6 +101,12 @@ void SNMPAgent::worker()
     throw std::runtime_error("No FD multiplexer found for the SNMP agent!");
   }
 
+  string threadName = "pdns-r/SNMP";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for SNMP thread: "<<strerror(retval)<<endl;
+  }
+
   int maxfd = 0;
   int block = 1;
   netsnmp_large_fd_set fdset;
index af0a17e4d9f56c30ba6876b64723b3a5ce157d70..d63da01ed689a0b83d26fe4bbf280dea24988714 100644 (file)
@@ -26,6 +26,7 @@
 #include "webserver.hh"
 #include "misc.hh"
 #include <thread>
+#include <pthread.h>
 #include <vector>
 #include "logger.hh"
 #include <stdio.h>
@@ -195,6 +196,11 @@ void WebServer::registerWebHandler(const string& url, HandlerFunction handler) {
 }
 
 static void *WebServerConnectionThreadStart(const WebServer* webServer, std::shared_ptr<Socket> client) {
+  string threadName = "pdns-r/webhndlr";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for webserver handler thread: "<<strerror(retval)<<endl;
+  }
   webServer->serveConnection(client);
   return nullptr;
 }