From: Pieter Lexis Date: Thu, 27 Sep 2018 15:08:38 +0000 (+0200) Subject: Move thread name setting to a single point X-Git-Tag: dnsdist-1.3.3~68^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=519f548473863120f32bea4eee94e345b9bfd0b1;p=thirdparty%2Fpdns.git Move thread name setting to a single point --- diff --git a/configure.ac b/configure.ac index 3317d0d4fe..e9b2a17a00 100644 --- a/configure.ac +++ b/configure.ac @@ -42,6 +42,7 @@ AC_DEFINE([_GNU_SOURCE], [1], m4_pattern_forbid([^_?PKG_[A-Z_]+$], [*** pkg.m4 missing, please install pkg-config]) PDNS_CHECK_OS +PTHREAD_SET_NAME PDNS_WITH_LUA PDNS_CHECK_LUA_HPP diff --git a/m4/ac_pthread_set_name.m4 b/m4/ac_pthread_set_name.m4 new file mode 100644 index 0000000000..4b2cb237ff --- /dev/null +++ b/m4/ac_pthread_set_name.m4 @@ -0,0 +1,71 @@ +# PTHREAD_SET_NAME(); +# Check which variant (if any) of pthread_set_name_np we have. +# ----------------------------------------------------------------------------- +AC_DEFUN([PTHREAD_SET_NAME], +[ + stored_LIBS="$LIBS" + LIBS="-lpthread" + # pthread setname (4 non-portable variants...) + AC_CHECK_HEADERS([pthread_np.h], [], [], [#include ]) + define(pthread_np_preamble,[ + #include + #if HAVE_PTHREAD_NP_H + # include + #endif + ]) + # 2-arg setname (e.g. Linux/glibc, QNX, IBM) + AC_MSG_CHECKING([for 2-arg pthread_setname_np]) + AC_LINK_IFELSE([AC_LANG_PROGRAM(pthread_np_preamble, [ + pthread_setname_np(pthread_self(), "foo") + ])], [ + AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_2, 1, [2-arg pthread_setname_np]) + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + + # 2-arg set_name (e.g. FreeBSD, OpenBSD) + AC_MSG_CHECKING([for 2-arg pthread_set_name_np]) + AC_LINK_IFELSE([AC_LANG_PROGRAM(pthread_np_preamble, [ + return pthread_set_name_np(pthread_self(), "foo"); + ])], [ + AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP_2, 1, [2-arg pthread_set_name_np]) + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + + # 2-arg void set_name (e.g. FreeBSD, OpenBSD) + AC_MSG_CHECKING([for 2-arg void pthread_set_name_np]) + AC_LINK_IFELSE([AC_LANG_PROGRAM(pthread_np_preamble, [ + pthread_set_name_np(pthread_self(), "foo"); + ])], [ + AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP_2_VOID, 1, [2-arg void pthread_set_name_np]) + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + + # 1-arg setname (e.g. Darwin) + AC_MSG_CHECKING([for 1-arg pthread_setname_np]) + AC_LINK_IFELSE([AC_LANG_PROGRAM(pthread_np_preamble, [ + return pthread_setname_np("foo"); + ])], [ + AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_1, 1, [1-arg pthread_setname_np]) + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + + # 3-arg setname (e.g. NetBSD) + AC_MSG_CHECKING([for 3-arg pthread_setname_np]) + AC_LINK_IFELSE([AC_LANG_PROGRAM(pthread_np_preamble, [ + return pthread_setname_np(pthread_self(), "foo", NULL); + ])], [ + AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_3, 1, [3-arg pthread_setname_np]) + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + ]) + ]) + ]) + ]) + ]) + LIBS=$stored_LIBS +]) diff --git a/pdns/Makefile.am b/pdns/Makefile.am index dfb1940859..05dbd8adbf 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -219,6 +219,7 @@ pdns_server_SOURCES = \ statbag.cc statbag.hh \ stubresolver.cc stubresolver.hh \ tcpreceiver.cc tcpreceiver.hh \ + threadname.hh threadname.cc \ tsigverifier.cc tsigverifier.hh \ tkey.cc \ ueberbackend.cc ueberbackend.hh \ @@ -328,6 +329,7 @@ pdnsutil_SOURCES = \ sstuff.hh \ statbag.cc \ stubresolver.cc stubresolver.hh \ + threadname.hh threadname.cc \ ueberbackend.cc \ unix_utility.cc \ zoneparser-tng.cc @@ -632,6 +634,7 @@ ixfrdist_SOURCES = \ sillyrecords.cc \ sstuff.hh \ statbag.cc \ + threadname.hh threadname.cc \ tsigverifier.cc tsigverifier.hh \ unix_utility.cc zoneparser-tng.cc @@ -715,6 +718,7 @@ dnstcpbench_SOURCES = \ sillyrecords.cc \ sstuff.hh \ statbag.cc \ + threadname.hh threadname.cc \ unix_utility.cc dnstcpbench_LDFLAGS = \ diff --git a/pdns/auth-carbon.cc b/pdns/auth-carbon.cc index f27e6ddb90..325bac326e 100644 --- a/pdns/auth-carbon.cc +++ b/pdns/auth-carbon.cc @@ -24,6 +24,7 @@ #endif #include "statbag.hh" #include "logger.hh" +#include "threadname.hh" #include "iputils.hh" #include "sstuff.hh" #include "arguments.hh" @@ -34,11 +35,7 @@ void* carbonDumpThread(void*) try { - string threadName = "pdns/carbonDump"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log< #include "dynhandler.hh" #include "dnsseckeeper.hh" +#include "threadname.hh" #ifdef HAVE_SYSTEMD #include @@ -367,11 +368,7 @@ void sendout(DNSPacket* a) void *qthread(void *number) try { - string threadName = "pdns/receiver"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log<(threadName.c_str())); - if (retval != 0) { - g_log<(threadName.c_str())); - if (retval != 0) { - g_log< +#include "threadname.hh" #include "dolog.hh" template @@ -139,11 +140,7 @@ DelayPipe::~DelayPipe() template void DelayPipe::worker() { - string threadName = "dnsdist/delayPi"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for DelayPipe worker thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/delayPi"); Combo c; for(;;) { /* this code is slightly too subtle, but I don't see how it could be any simpler. diff --git a/pdns/distributor.hh b/pdns/distributor.hh index 2abd21684e..cf005127ca 100644 --- a/pdns/distributor.hh +++ b/pdns/distributor.hh @@ -27,6 +27,7 @@ #include #include #include +#include "threadname.hh" #include #include "logger.hh" #include "dns.hh" @@ -173,11 +174,7 @@ templateMultiThreadDistributorvoid *MultiThreadDistributor::makeThread(void *p) { - string threadName = "pdns/distributo"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log<(p); int ournum=us->d_running++; diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index c880289d50..da1e0fd7df 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -28,6 +28,7 @@ #include "namespaces.hh" #include "dnsdist.hh" +#include "threadname.hh" GlobalStateHolder > g_carbon; static time_t s_start=time(0); @@ -39,11 +40,7 @@ uint64_t uptimeOfProcess(const std::string& str) void* carbonDumpThread() try { - string threadName = "dnsdist/carbon"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for carbon thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/carbon"); auto localCarbon = g_carbon.getLocal(); for(int numloops=0;;++numloops) { if(localCarbon->empty()) { diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index c9fe6f4f97..1a8419abe0 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -37,6 +37,7 @@ #include "dnsdist.hh" #include "dnsdist-console.hh" #include "sodcrypto.hh" +#include "threadname.hh" GlobalStateHolder g_consoleACL; vector > g_confDelta; @@ -535,11 +536,7 @@ 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(threadname.c_str())); - if (retval != 0) { - warnlog("could not set thread name %s for control client thread: %s", threadname, strerror(retval)); - } + setThreadName("dnsdist/conscli"); setTCPNoDelay(fd); SodiumNonce theirs, ours, readingNonce, writingNonce; ours.init(); @@ -670,11 +667,7 @@ catch(std::exception& e) void controlThread(int fd, ComboAddress local) try { - string threadName = "dnsdist/control"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for control console thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/control"); ComboAddress client; int sock; auto localACL = g_consoleACL.getLocal(); diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index 4dd98797d1..ac9705f67f 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -19,7 +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 +#include "threadname.hh" #include "dnsdist.hh" #include "dnsdist-ecs.hh" #include "dnsdist-lua.hh" @@ -212,11 +212,7 @@ std::map TeeAction::getStats() const void TeeAction::worker() { - string threadName = "dnsdist/TeeWork"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for TeeAction worker thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/TeeWork"); char packet[1500]; int res=0; struct dnsheader* dh=(struct dnsheader*)packet; diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 69d653d4bb..6519cbba5f 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -29,6 +29,7 @@ #include "lock.hh" #include "gettime.hh" #include "tcpiohandler.hh" +#include "threadname.hh" #include #include @@ -237,11 +238,7 @@ 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(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for TCP Client thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/tcpClie"); bool outstanding = false; time_t lastTCPCleanup = time(nullptr); @@ -676,11 +673,7 @@ void* tcpClientThread(int pipefd) */ void* tcpAcceptorThread(void* p) { - string threadName = "dnsdist/tcpAcce"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for TCP acceptor thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/tcpAcce"); ClientState* cs = (ClientState*) p; bool tcpClientCountIncremented = false; ComboAddress remote; diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index 4be3811958..12cc28aea0 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -25,7 +25,7 @@ #include "ext/incbin/incbin.h" #include "dolog.hh" #include -#include +#include "threadname.hh" #include #include #include "namespaces.hh" @@ -243,11 +243,7 @@ static json11::Json::array someResponseRulesToJson(GlobalStateHolder>* static void connectionThread(int sock, ComboAddress remote, string password, string apiKey, const boost::optional >& customHeaders) { - string threadName = "dnsdist/webConn"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for webserver connection thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/webConn"); using namespace json11; vinfolog("Webserver handling connection from %s", remote.toStringWithPort()); @@ -820,11 +816,7 @@ 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 >& customHeaders) { - string threadName = "dnsdist/webserv"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for webserver thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/webserv"); warnlog("Webserver launched on %s", local.toStringWithPort()); for(;;) { try { diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 7cf206ffb1..9e985bab1a 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -60,6 +60,7 @@ #include "misc.hh" #include "sodcrypto.hh" #include "sstuff.hh" +#include "threadname.hh" #include "xpf.hh" thread_local boost::uuids::random_generator t_uuidGenerator; @@ -426,11 +427,7 @@ static void pickBackendSocketsReadyForReceiving(const std::shared_ptr dss) try { - string threadName = "dnsdist/respond"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for responder thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/respond"); auto localRespRulactions = g_resprulactions.getLocal(); #ifdef HAVE_DNSCRYPT char packet[4096 + DNSCRYPT_MAX_RESPONSE_PADDING_AND_MAC_SIZE]; @@ -1660,11 +1657,7 @@ 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(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for UDP client thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/udpClie"); LocalHolders holders; #if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) @@ -1860,11 +1853,7 @@ std::atomic g_cacheCleaningPercentage{100}; void* maintThread() { - string threadName = "dnsdist/main"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for main thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/main"); int interval = 1; size_t counter = 0; int32_t secondsToWaitLog = 0; @@ -1911,11 +1900,7 @@ void* maintThread() void* healthChecksThread() { - string threadName = "dnsdist/healthC"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - warnlog("Could not set thread name %s for health check thread: %s", threadName, strerror(retval)); - } + setThreadName("dnsdist/healthC"); int interval = 1; diff --git a/pdns/dnsdistdist/Makefile.am b/pdns/dnsdistdist/Makefile.am index c7c563c7da..0c8cee1e28 100644 --- a/pdns/dnsdistdist/Makefile.am +++ b/pdns/dnsdistdist/Makefile.am @@ -138,6 +138,7 @@ dnsdist_SOURCES = \ sstuff.hh \ statnode.cc statnode.hh \ tcpiohandler.cc tcpiohandler.hh \ + threadname.hh threadname.cc \ xpf.cc xpf.hh \ ext/luawrapper/include/LuaContext.hpp \ ext/json11/json11.cpp \ diff --git a/pdns/dnsdistdist/configure.ac b/pdns/dnsdistdist/configure.ac index 9bc010e3ff..e1ae7e9acc 100644 --- a/pdns/dnsdistdist/configure.ac +++ b/pdns/dnsdistdist/configure.ac @@ -10,6 +10,10 @@ AC_PROG_CXX AC_LANG([C++]) AC_GNU_SOURCE +AC_DEFINE([DNSDIST], [1], + [This is dnsdist] +) + LT_PREREQ([2.2.2]) LT_INIT([disable-static]) @@ -20,6 +24,7 @@ PDNS_CHECK_LIBEDIT PDNS_CHECK_CLOCK_GETTIME PDNS_CHECK_OS +PTHREAD_SET_NAME PDNS_CHECK_NETWORK_LIBS PDNS_CHECK_PTHREAD_NP PDNS_CHECK_SECURE_MEMSET diff --git a/pdns/dnsdistdist/m4/ac_pthread_set_name.m4 b/pdns/dnsdistdist/m4/ac_pthread_set_name.m4 new file mode 120000 index 0000000000..a0aa10263d --- /dev/null +++ b/pdns/dnsdistdist/m4/ac_pthread_set_name.m4 @@ -0,0 +1 @@ +../../../m4/ac_pthread_set_name.m4 \ No newline at end of file diff --git a/pdns/dnsdistdist/threadname.cc b/pdns/dnsdistdist/threadname.cc new file mode 120000 index 0000000000..b850aaf113 --- /dev/null +++ b/pdns/dnsdistdist/threadname.cc @@ -0,0 +1 @@ +../threadname.cc \ No newline at end of file diff --git a/pdns/dnsdistdist/threadname.hh b/pdns/dnsdistdist/threadname.hh new file mode 120000 index 0000000000..df5c41272b --- /dev/null +++ b/pdns/dnsdistdist/threadname.hh @@ -0,0 +1 @@ +../threadname.hh \ No newline at end of file diff --git a/pdns/dnsproxy.cc b/pdns/dnsproxy.cc index 18c3d4c4b2..41ec9d84ac 100644 --- a/pdns/dnsproxy.cc +++ b/pdns/dnsproxy.cc @@ -34,6 +34,7 @@ #include "dns_random.hh" #include "stubresolver.hh" #include "arguments.hh" +#include "threadname.hh" extern StatBag S; @@ -175,11 +176,7 @@ int DNSProxy::getID_locked() void DNSProxy::mainloop(void) { - string threadName = "pdns/dnsproxy"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log< #include #include @@ -174,11 +175,7 @@ vector g_queries; static void* worker(void*) { - string threadName = "dnstcpb/worker"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - cerr<<"Could not set thread name "<= g_queries.size()) diff --git a/pdns/dynlistener.cc b/pdns/dynlistener.cc index 05036c803b..381054c87e 100644 --- a/pdns/dynlistener.cc +++ b/pdns/dynlistener.cc @@ -52,6 +52,7 @@ #include "dnspacket.hh" #include "logger.hh" #include "statbag.hh" +#include "threadname.hh" extern StatBag S; @@ -216,11 +217,7 @@ void DynListener::go() void *DynListener::theListenerHelper(void *p) { - string threadName = "pdns/ctrlListen"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log<(p); us->theListener(); g_log< #include #include -#include +#include "threadname.hh" #include #include #include @@ -235,11 +235,7 @@ static void updateCurrentZoneInfo(const DNSName& domain, std::shared_ptr(threadName.c_str())); - if (retval != 0) { - g_log< lastCheck; // Initialize the serials we have @@ -774,11 +770,7 @@ static void handleTCPRequest(int fd, boost::any&) { /* Thread to handle TCP traffic */ static void tcpWorker(int tid) { - string threadName = "ixfrdist/tcpWor"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log< #include #include +#include "threadname.hh" #include #include #include "logger.hh" @@ -99,11 +100,7 @@ bool NODDB::init(bool ignore_pid) { void NODDB::housekeepingThread() { - string threadName = "pdns-r/NOD-hk"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log< -#include +#include "threadname.hh" #include "recpacketcache.hh" #include "utility.hh" #include "dns_random.hh" @@ -3735,11 +3735,7 @@ try auto& threadInfo = s_threadInfos.at(t_id); static string threadPrefix = "pdns-r/"; - - auto retval = pthread_setname_np(pthread_self(), const_cast((threadPrefix + threadName).c_str())); - if (retval != 0) { - g_log< -#include +#include "threadname.hh" #include "remote_logger.hh" +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef PDNS_CONFIG_ARGS #include "logger.hh" #define WE_ARE_RECURSOR @@ -47,14 +49,7 @@ void RemoteLogger::worker() #else string threadName = "dnsdist/remLog"; #endif - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { -#ifdef WE_ARE_RECURSOR - g_log< #include "dnsparser.hh" #include "dnsrecords.hh" #include "ixfr.hh" @@ -8,6 +7,7 @@ #include "rec-lua-conf.hh" #include "rpzloader.hh" #include "zoneparser-tng.hh" +#include "threadname.hh" static Netmask makeNetmaskFromRPZ(const DNSName& name) { @@ -340,12 +340,7 @@ static bool dumpZoneToDisk(const DNSName& zoneName, const std::shared_ptr masters, boost::optional defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, const uint16_t axfrTimeout, std::shared_ptr sr, std::string dumpZoneFileName, uint64_t configGeneration) { - string threadName = "pdns-r/RPZIXFR"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log<(threadName.c_str())); - if (retval != 0) { -#ifdef RECURSOR - g_log< #include "auth-packetcache.hh" #include "utility.hh" +#include "threadname.hh" #include "dnssecinfra.hh" #include "dnsseckeeper.hh" #include @@ -252,11 +253,7 @@ void TCPNameserver::decrementClientCount(const ComboAddress& remote) void *TCPNameserver::doConnection(void *data) { - string threadName = "pdns/tcpConnect"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log< packet; // Fix gcc-4.0 error (on AMD64) int fd=(int)(long)data; // gotta love C (generates a harmless warning on opteron) @@ -1340,11 +1337,7 @@ TCPNameserver::TCPNameserver() //! Start of TCP operations thread, we launch a new thread for each incoming TCP question void TCPNameserver::thread() { - string threadName = "pdns/tcpnameser"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log< +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#ifdef DNSDIST +#include "dolog.hh" +#else +#include "logger.hh" +#endif +#include "threadname.hh" + +void setThreadName(const std::string& threadName) { + int retval = 0; + +#ifdef HAVE_PTHREAD_SETNAME_NP_2 + retval = pthread_setname_np(pthread_self(), threadName.c_str()); +#endif +#ifdef HAVE_PTHREAD_SET_NAME_NP_2 + retval = pthread_set_name_np(pthread_self(), threadName.c_str()); +#endif +#ifdef HAVE_PTHREAD_SET_NAME_NP_2_VOID + pthread_set_name_np(pthread_self(), threadName.c_str()); +#endif +#ifdef HAVE_PTHREAD_SETNAME_NP_1 + retval = pthread_setname_np(threadName.c_str()); +#endif +#ifdef HAVE_PTHREAD_SETNAME_NP_3 + retval = pthread_setname_np(pthread_self(), threadname.c_str(), nullptr); +#endif + + if (retval != 0) { +#ifdef DNSDIST + warnlog("Could not set thread name %s for thread: %s", threadName, strerror(retval)); +#else + g_log< + +void setThreadName(const std::string& threadName); diff --git a/pdns/webserver.cc b/pdns/webserver.cc index d63da01ed6..1b2706c990 100644 --- a/pdns/webserver.cc +++ b/pdns/webserver.cc @@ -26,7 +26,7 @@ #include "webserver.hh" #include "misc.hh" #include -#include +#include "threadname.hh" #include #include "logger.hh" #include @@ -196,11 +196,7 @@ void WebServer::registerWebHandler(const string& url, HandlerFunction handler) { } static void *WebServerConnectionThreadStart(const WebServer* webServer, std::shared_ptr client) { - string threadName = "pdns-r/webhndlr"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log<serveConnection(client); return nullptr; } diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index abc16e2fae..e025d2b434 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -44,6 +44,7 @@ #include "zoneparser-tng.hh" #include "common_startup.hh" #include "auth-caches.hh" +#include "threadname.hh" using json11::Json; @@ -75,11 +76,7 @@ void AuthWebServer::go() void AuthWebServer::statThread() { try { - string threadName = "pdns/statHelper"; - auto retval = pthread_setname_np(pthread_self(), const_cast(threadName.c_str())); - if (retval != 0) { - g_log<(threadName.c_str())); - if (retval != 0) { - g_log<registerApiHandler("/api/v1/servers/localhost/cache/flush", &apiServerCacheFlush); d_ws->registerApiHandler("/api/v1/servers/localhost/config", &apiServerConfig);