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
--- /dev/null
+# 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 <pthread.h>])
+ define(pthread_np_preamble,[
+ #include <pthread.h>
+ #if HAVE_PTHREAD_NP_H
+ # include <pthread_np.h>
+ #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
+])
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 \
sstuff.hh \
statbag.cc \
stubresolver.cc stubresolver.hh \
+ threadname.hh threadname.cc \
ueberbackend.cc \
unix_utility.cc \
zoneparser-tng.cc
sillyrecords.cc \
sstuff.hh \
statbag.cc \
+ threadname.hh threadname.cc \
tsigverifier.cc tsigverifier.hh \
unix_utility.cc zoneparser-tng.cc
sillyrecords.cc \
sstuff.hh \
statbag.cc \
+ threadname.hh threadname.cc \
unix_utility.cc
dnstcpbench_LDFLAGS = \
#endif
#include "statbag.hh"
#include "logger.hh"
+#include "threadname.hh"
#include "iputils.hh"
#include "sstuff.hh"
#include "arguments.hh"
void* carbonDumpThread(void*)
try
{
- string threadName = "pdns/carbonDump";
- 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 Carbon dump thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/carbonDump");
extern StatBag S;
string hostname=arg()["carbon-ourname"];
#include <sys/resource.h>
#include "dynhandler.hh"
#include "dnsseckeeper.hh"
+#include "threadname.hh"
#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
void *qthread(void *number)
try
{
- string threadName = "pdns/receiver";
- 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 receiver thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/receiver");
DNSPacket *P;
DNSDistributor *distributor = DNSDistributor::Create(::arg().asNum("distributor-threads", 1)); // the big dispatcher!
#include "dns.hh"
#include "arguments.hh"
#include "packetcache.hh"
+#include "threadname.hh"
// there can be MANY OF THESE
void CommunicatorClass::retrievalLoopThread(void)
{
- string threadName = "pdns/comm-retre";
- 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 retrieval thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/comm-retre");
for(;;) {
d_suck_sem.wait();
SuckRequest sr;
void CommunicatorClass::mainloop(void)
{
try {
- string threadName = "pdns/comm-main";
- 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 communicator main thread: "<<strerror(retval)<<endl;
- }
-
+ setThreadName("pdns/comm-main");
signal(SIGPIPE,SIG_IGN);
g_log<<Logger::Error<<"Master/slave communicator launching"<<endl;
PacketHandler P;
#include "misc.hh"
#include "gettime.hh"
#include <thread>
+#include "threadname.hh"
#include "dolog.hh"
template<class T>
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));
- }
+ setThreadName("dnsdist/delayPi");
Combo c;
for(;;) {
/* this code is slightly too subtle, but I don't see how it could be any simpler.
#include <queue>
#include <vector>
#include <pthread.h>
+#include "threadname.hh"
#include <unistd.h>
#include "logger.hh"
#include "dns.hh"
// start of a new thread
template<class Answer, class Question, class Backend>void *MultiThreadDistributor<Answer,Question,Backend>::makeThread(void *p)
{
- string threadName = "pdns/distributo";
- 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 distributor thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/distributo");
pthread_detach(pthread_self());
MultiThreadDistributor *us=static_cast<MultiThreadDistributor *>(p);
int ournum=us->d_running++;
#include "namespaces.hh"
#include "dnsdist.hh"
+#include "threadname.hh"
GlobalStateHolder<vector<CarbonConfig> > g_carbon;
static time_t s_start=time(0);
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));
- }
+ setThreadName("dnsdist/carbon");
auto localCarbon = g_carbon.getLocal();
for(int numloops=0;;++numloops) {
if(localCarbon->empty()) {
#include "dnsdist.hh"
#include "dnsdist-console.hh"
#include "sodcrypto.hh"
+#include "threadname.hh"
GlobalStateHolder<NetmaskGroup> g_consoleACL;
vector<pair<struct timeval, string> > g_confDelta;
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));
- }
+ setThreadName("dnsdist/conscli");
setTCPNoDelay(fd);
SodiumNonce theirs, ours, readingNonce, writingNonce;
ours.init();
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));
- }
+ setThreadName("dnsdist/control");
ComboAddress client;
int sock;
auto localACL = g_consoleACL.getLocal();
* 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 "threadname.hh"
#include "dnsdist.hh"
#include "dnsdist-ecs.hh"
#include "dnsdist-lua.hh"
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));
- }
+ setThreadName("dnsdist/TeeWork");
char packet[1500];
int res=0;
struct dnsheader* dh=(struct dnsheader*)packet;
#include "lock.hh"
#include "gettime.hh"
#include "tcpiohandler.hh"
+#include "threadname.hh"
#include <thread>
#include <atomic>
/* 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));
- }
+ setThreadName("dnsdist/tcpClie");
bool outstanding = false;
time_t lastTCPCleanup = time(nullptr);
*/
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));
- }
+ setThreadName("dnsdist/tcpAcce");
ClientState* cs = (ClientState*) p;
bool tcpClientCountIncremented = false;
ComboAddress remote;
#include "ext/incbin/incbin.h"
#include "dolog.hh"
#include <thread>
-#include <pthread.h>
+#include "threadname.hh"
#include <sstream>
#include <yahttp/yahttp.hpp>
#include "namespaces.hh"
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));
- }
+ setThreadName("dnsdist/webConn");
using namespace json11;
vinfolog("Webserver handling connection from %s", remote.toStringWithPort());
}
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));
- }
+ setThreadName("dnsdist/webserv");
warnlog("Webserver launched on %s", local.toStringWithPort());
for(;;) {
try {
#include "misc.hh"
#include "sodcrypto.hh"
#include "sstuff.hh"
+#include "threadname.hh"
#include "xpf.hh"
thread_local boost::uuids::random_generator t_uuidGenerator;
// 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));
- }
+ setThreadName("dnsdist/respond");
auto localRespRulactions = g_resprulactions.getLocal();
#ifdef HAVE_DNSCRYPT
char packet[4096 + DNSCRYPT_MAX_RESPONSE_PADDING_AND_MAC_SIZE];
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));
- }
+ setThreadName("dnsdist/udpClie");
LocalHolders holders;
#if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE)
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));
- }
+ setThreadName("dnsdist/main");
int interval = 1;
size_t counter = 0;
int32_t secondsToWaitLog = 0;
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));
- }
+ setThreadName("dnsdist/healthC");
int interval = 1;
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 \
AC_LANG([C++])
AC_GNU_SOURCE
+AC_DEFINE([DNSDIST], [1],
+ [This is dnsdist]
+)
+
LT_PREREQ([2.2.2])
LT_INIT([disable-static])
PDNS_CHECK_CLOCK_GETTIME
PDNS_CHECK_OS
+PTHREAD_SET_NAME
PDNS_CHECK_NETWORK_LIBS
PDNS_CHECK_PTHREAD_NP
PDNS_CHECK_SECURE_MEMSET
--- /dev/null
+../../../m4/ac_pthread_set_name.m4
\ No newline at end of file
--- /dev/null
+../threadname.cc
\ No newline at end of file
--- /dev/null
+../threadname.hh
\ No newline at end of file
#include "dns_random.hh"
#include "stubresolver.hh"
#include "arguments.hh"
+#include "threadname.hh"
extern StatBag S;
void DNSProxy::mainloop(void)
{
- string threadName = "pdns/dnsproxy";
- 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 DNS proxy thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/dnsproxy");
try {
char buffer[1500];
ssize_t len;
#include "dnswriter.hh"
#include "dnsrecords.hh"
#include "statbag.hh"
+#include "threadname.hh"
#include <netinet/tcp.h>
#include <boost/array.hpp>
#include <boost/program_options.hpp>
static void* worker(void*)
{
- string threadName = "dnstcpb/worker";
- auto retval = pthread_setname_np(pthread_self(), const_cast<char*>(threadName.c_str()));
- if (retval != 0) {
- cerr<<"Could not set thread name "<<threadName<<" for wthread: "<<strerror(retval)<<endl;
- }
+ setThreadName("dnstcpb/worker");
for(;;) {
unsigned int pos = g_pos++;
if(pos >= g_queries.size())
#include "dnspacket.hh"
#include "logger.hh"
#include "statbag.hh"
+#include "threadname.hh"
extern StatBag S;
void *DynListener::theListenerHelper(void *p)
{
- string threadName = "pdns/ctrlListen";
- 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 control socket listener thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/ctrlListen");
DynListener *us=static_cast<DynListener *>(p);
us->theListener();
g_log<<Logger::Error<<"Control listener aborted, please file a bug!"<<endl;
#include <sys/stat.h>
#include <mutex>
#include <thread>
-#include <pthread.h>
+#include "threadname.hh"
#include <dirent.h>
#include <queue>
#include <condition_variable>
}
void updateThread(const string& workdir, const uint16_t& keep, const uint16_t& axfrTimeout) {
- string threadName = "ixfrdist/update";
- 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 update thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("ixfrdist/update");
std::map<DNSName, time_t> lastCheck;
// Initialize the serials we have
/* Thread to handle TCP traffic
*/
static void tcpWorker(int tid) {
- string threadName = "ixfrdist/tcpWor";
- 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 update thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("ixfrdist/tcpWor");
string prefix = "TCP Worker " + std::to_string(tid) + ": ";
while(true) {
#include <iomanip>
#include <ctime>
#include <thread>
+#include "threadname.hh"
#include <unistd.h>
#include <boost/filesystem.hpp>
#include "logger.hh"
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;
- }
+ setThreadName("pdns-r/NOD-hk");
for (;;) {
sleep(d_snapshot_interval);
{
#endif
#include "ws-recursor.hh"
#include <thread>
-#include <pthread.h>
+#include "threadname.hh"
#include "recpacketcache.hh"
#include "utility.hh"
#include "dns_random.hh"
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;
- }
+ setThreadName(threadPrefix + threadName);
SyncRes tmp(g_now); // make sure it allocates tsstorage before we do anything, like primeHints or so..
SyncRes::setDomainMap(g_initialDomainMap);
sstuff.hh \
stable-bloom.hh \
syncres.cc syncres.hh \
+ threadname.hh threadname.cc \
tsigverifier.cc tsigverifier.hh \
ueberbackend.hh \
unix_utility.cc \
PDNS_CHECK_OS
PDNS_CHECK_NETWORK_LIBS
+PTHREAD_SET_NAME
# Boost Context was introduced in 1.51 (Aug 2012), but there was an immediate
# API break in 1.52 (Nov 2012), so we only support that, and later.
--- /dev/null
+../../../m4/ac_pthread_set_name.m4
\ No newline at end of file
--- /dev/null
+../threadname.cc
\ No newline at end of file
--- /dev/null
+../threadname.hh
\ No newline at end of file
#include <unistd.h>
-#include <pthread.h>
+#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
#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
- }
+ setThreadName(threadName);
while(true) {
std::string data;
{
-#include <pthread.h>
#include "dnsparser.hh"
#include "dnsrecords.hh"
#include "ixfr.hh"
#include "rec-lua-conf.hh"
#include "rpzloader.hh"
#include "zoneparser-tng.hh"
+#include "threadname.hh"
static Netmask makeNetmaskFromRPZ(const DNSName& name)
{
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;
- }
-
+ setThreadName("pdns-r/RPZIXFR");
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 */
#include "snmp-agent.hh"
#include "misc.hh"
+#include "threadname.hh"
#ifdef RECURSOR
#include "logger.hh"
#else
#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
- }
+ setThreadName(threadName);
int maxfd = 0;
int block = 1;
#include <boost/algorithm/string.hpp>
#include "auth-packetcache.hh"
#include "utility.hh"
+#include "threadname.hh"
#include "dnssecinfra.hh"
#include "dnsseckeeper.hh"
#include <cstdio>
void *TCPNameserver::doConnection(void *data)
{
- string threadName = "pdns/tcpConnect";
- 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 TCP nameserver connection thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/tcpConnect");
shared_ptr<DNSPacket> packet;
// Fix gcc-4.0 error (on AMD64)
int fd=(int)(long)data; // gotta love C (generates a harmless warning on opteron)
//! 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<char*>(threadName.c_str()));
- if (retval != 0) {
- g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for TCP nameserver thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/tcpnameser");
try {
for(;;) {
int fd;
--- /dev/null
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <string.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <pthread.h>
+#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<<Logger::Warning<<"Could not set thread name "<<threadName<<" for thread: "<<strerror(retval)<<endl;
+#endif
+ }
+}
+
--- /dev/null
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#pragma once
+#include <string>
+
+void setThreadName(const std::string& threadName);
#include "webserver.hh"
#include "misc.hh"
#include <thread>
-#include <pthread.h>
+#include "threadname.hh"
#include <vector>
#include "logger.hh"
#include <stdio.h>
}
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;
- }
+ setThreadName("pdns-r/webhndlr");
webServer->serveConnection(client);
return nullptr;
}
#include "zoneparser-tng.hh"
#include "common_startup.hh"
#include "auth-caches.hh"
+#include "threadname.hh"
using json11::Json;
void AuthWebServer::statThread()
{
try {
- string threadName = "pdns/statHelper";
- 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 stat helper thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/statHelper");
for(;;) {
d_queries.submit(S.read("udp-queries"));
d_cachehits.submit(S.read("packetcache-hit"));
void AuthWebServer::webThread()
{
try {
- string threadName = "pdns/webserver";
- 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 thread: "<<strerror(retval)<<endl;
- }
+ setThreadName("pdns/webserver");
if(::arg().mustDo("api")) {
d_ws->registerApiHandler("/api/v1/servers/localhost/cache/flush", &apiServerCacheFlush);
d_ws->registerApiHandler("/api/v1/servers/localhost/config", &apiServerConfig);