]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: name all threads
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 27 Sep 2018 09:34:25 +0000 (11:34 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Thu, 27 Sep 2018 09:34:25 +0000 (11:34 +0200)
pdns/delaypipe.cc
pdns/dnsdist-carbon.cc
pdns/dnsdist-console.cc
pdns/dnsdist-lua-actions.cc
pdns/dnsdist-tcp.cc
pdns/dnsdist-web.cc
pdns/dnsdist.cc
pdns/remote_logger.cc
pdns/snmp-agent.cc

index aebf217c79f426e42043b842a12b797b3bdbbc92..e4e557bc7b9f83fee7b04a52500fba43ad43a8de 100644 (file)
@@ -23,6 +23,7 @@
 #include "misc.hh"
 #include "gettime.hh"
 #include <thread>
+#include "dolog.hh"
 
 template<class T>
 ObjectPipe<T>::ObjectPipe()
@@ -138,6 +139,11 @@ DelayPipe<T>::~DelayPipe()
 template<class T>
 void DelayPipe<T>::worker()
 {
+  string threadName = "dnsdist/delayPi";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for DelayPipe worker thread: %s", threadName, strerror(retval));
+  }
   Combo c;
   for(;;) {
     /* this code is slightly too subtle, but I don't see how it could be any simpler.
index 860657d586b0d16c20aace766898ff508d9a1c47..c880289d50407f2bc511e22ce988ef90bbc3eb5d 100644 (file)
@@ -39,6 +39,11 @@ uint64_t uptimeOfProcess(const std::string& str)
 void* carbonDumpThread()
 try
 {
+  string threadName = "dnsdist/carbon";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for carbon thread: %s", threadName, strerror(retval));
+  }
   auto localCarbon = g_carbon.getLocal();
   for(int numloops=0;;++numloops) {
     if(localCarbon->empty()) {
index 4eda5b0553a3159c9083ba2d94f5281f6896b891..c9fe6f4f97c40481215e455a67b725737b42d6c2 100644 (file)
@@ -535,6 +535,11 @@ char** my_completion( const char * text , int start,  int end)
 static void controlClientThread(int fd, ComboAddress client)
 try
 {
+  string threadname = "dnsdist/conscli";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadname.c_str()));
+  if (retval != 0) {
+    warnlog("could not set thread name %s for control client thread: %s", threadname, strerror(retval));
+  }
   setTCPNoDelay(fd);
   SodiumNonce theirs, ours, readingNonce, writingNonce;
   ours.init();
@@ -665,6 +670,11 @@ catch(std::exception& e)
 void controlThread(int fd, ComboAddress local)
 try
 {
+  string threadName = "dnsdist/control";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for control console thread: %s", threadName, strerror(retval));
+  }
   ComboAddress client;
   int sock;
   auto localACL = g_consoleACL.getLocal();
index 377add214c5aaee840c3380bf7853427baf500e8..4dd98797d1766fce76a9218e16844e46a95186f6 100644 (file)
@@ -19,6 +19,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
+#include <pthread.h>
 #include "dnsdist.hh"
 #include "dnsdist-ecs.hh"
 #include "dnsdist-lua.hh"
@@ -211,6 +212,11 @@ std::map<string,double> TeeAction::getStats() const
 
 void TeeAction::worker()
 {
+  string threadName = "dnsdist/TeeWork";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for TeeAction worker thread: %s", threadName, strerror(retval));
+  }
   char packet[1500];
   int res=0;
   struct dnsheader* dh=(struct dnsheader*)packet;
index 5ca8ba071777e332f2440c8f579b2a70bc09730f..69d653d4bbf74e6cafcefbb15bd72f92c1dbd2c4 100644 (file)
@@ -237,6 +237,12 @@ void* tcpClientThread(int pipefd)
   /* we get launched with a pipe on which we receive file descriptors from clients that we own
      from that point on */
 
+  string threadName = "dnsdist/tcpClie";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for TCP Client thread: %s", threadName, strerror(retval));
+  }
+
   bool outstanding = false;
   time_t lastTCPCleanup = time(nullptr);
   
@@ -670,6 +676,11 @@ void* tcpClientThread(int pipefd)
 */
 void* tcpAcceptorThread(void* p)
 {
+  string threadName = "dnsdist/tcpAcce";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for TCP acceptor thread: %s", threadName, strerror(retval));
+  }
   ClientState* cs = (ClientState*) p;
   bool tcpClientCountIncremented = false;
   ComboAddress remote;
index e2e756c8ea629e95807d0f8845cf8552f64f6641..4be381195883c2d33a5d8e46ed11265cd3307dbe 100644 (file)
@@ -25,6 +25,7 @@
 #include "ext/incbin/incbin.h"
 #include "dolog.hh"
 #include <thread>
+#include <pthread.h>
 #include <sstream>
 #include <yahttp/yahttp.hpp>
 #include "namespaces.hh"
@@ -242,6 +243,12 @@ static json11::Json::array someResponseRulesToJson(GlobalStateHolder<vector<T>>*
 
 static void connectionThread(int sock, ComboAddress remote, string password, string apiKey, const boost::optional<std::map<std::string, std::string> >& customHeaders)
 {
+  string threadName = "dnsdist/webConn";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for webserver connection thread: %s", threadName, strerror(retval));
+  }
+
   using namespace json11;
   vinfolog("Webserver handling connection from %s", remote.toStringWithPort());
 
@@ -813,6 +820,11 @@ static void connectionThread(int sock, ComboAddress remote, string password, str
 }
 void dnsdistWebserverThread(int sock, const ComboAddress& local, const std::string& password, const std::string& apiKey, const boost::optional<std::map<std::string, std::string> >& customHeaders)
 {
+  string threadName = "dnsdist/webserv";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for webserver thread: %s", threadName, strerror(retval));
+  }
   warnlog("Webserver launched on %s", local.toStringWithPort());
   for(;;) {
     try {
index 4173879f6de4f12c405d3e63b9f73c1659338c16..7cf206ffb10407e4de7eca9c78474da83312aeff 100644 (file)
@@ -426,6 +426,11 @@ static void pickBackendSocketsReadyForReceiving(const std::shared_ptr<Downstream
 // listens on a dedicated socket, lobs answers from downstream servers to original requestors
 void* responderThread(std::shared_ptr<DownstreamState> dss)
 try {
+  string threadName = "dnsdist/respond";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for responder thread: %s", threadName, strerror(retval));
+  }
   auto localRespRulactions = g_resprulactions.getLocal();
 #ifdef HAVE_DNSCRYPT
   char packet[4096 + DNSCRYPT_MAX_RESPONSE_PADDING_AND_MAC_SIZE];
@@ -1655,6 +1660,11 @@ static void MultipleMessagesUDPClientThread(ClientState* cs, LocalHolders& holde
 static void* udpClientThread(ClientState* cs)
 try
 {
+  string threadName = "dnsdist/udpClie";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for UDP client thread: %s", threadName, strerror(retval));
+  }
   LocalHolders holders;
 
 #if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE)
@@ -1850,6 +1860,11 @@ std::atomic<uint16_t> g_cacheCleaningPercentage{100};
 
 void* maintThread()
 {
+  string threadName = "dnsdist/main";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for main thread: %s", threadName, strerror(retval));
+  }
   int interval = 1;
   size_t counter = 0;
   int32_t secondsToWaitLog = 0;
@@ -1896,6 +1911,12 @@ void* maintThread()
 
 void* healthChecksThread()
 {
+  string threadName = "dnsdist/healthC";
+  auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
+  if (retval != 0) {
+    warnlog("Could not set thread name %s for health check thread: %s", threadName, strerror(retval));
+  }
+
   int interval = 1;
 
   for(;;) {
index c186e017a9a17c3e2604d3831a6a74190730080f..657c493b7339b7b3d78bb47310e72ea3a38c3b2c 100644 (file)
@@ -42,10 +42,18 @@ void RemoteLogger::busyReconnectLoop()
 
 void RemoteLogger::worker()
 {
+#ifdef WE_ARE_RECURSOR
   string threadName = "pdns-r/remLog";
+#else
+  string threadName = "dnsdist/remLog";
+#endif
   auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
   if (retval != 0) {
+#ifdef WE_ARE_RECURSOR
     g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for Remote Logger thread: "<<strerror(retval)<<endl;
+#else
+    warnlog("Could not set thread name %s for Remote Logger thread: %s", threadName, strerror(retval));
+#endif
   }
   while(true) {
     std::string data;
index 7277a05db2dd033ddaf88154a93340946ea34d5b..3c739ffb2d1b2255c6d518fe02c5d19e88f2f5d8 100644 (file)
@@ -1,6 +1,10 @@
 #include "snmp-agent.hh"
 #include "misc.hh"
+#ifdef RECURSOR
 #include "logger.hh"
+#else
+#include "dolog.hh"
+#endif
 
 #ifdef HAVE_NET_SNMP
 
@@ -101,10 +105,18 @@ void SNMPAgent::worker()
     throw std::runtime_error("No FD multiplexer found for the SNMP agent!");
   }
 
+#ifdef RECURSOR
   string threadName = "pdns-r/SNMP";
+#else
+  string threadName = "dnsdist/SNMP";
+#endif
   auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
   if (retval != 0) {
+#ifdef RECURSOR
     g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for SNMP thread: "<<strerror(retval)<<endl;
+#else
+    warnlog("Could not set thread name %s for SNMP thread: %s", threadName, strerror(retval));
+#endif
   }
 
   int maxfd = 0;