From: Josh Soref Date: Thu, 30 Dec 2021 03:40:10 +0000 (-0500) Subject: Try shorter thread names X-Git-Tag: auth-4.7.0-alpha1~89^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3813e097ef9b4053009372e8009915bcd496a63;p=thirdparty%2Fpdns.git Try shorter thread names https://man7.org/linux/man-pages/man3/pthread_setname_np.3.html ... The thread name is a meaningful C language string, whose length is restricted to 16 characters, including the terminating null byte ('\0'). --- diff --git a/pdns/threadname.cc b/pdns/threadname.cc index 249248a623..35fa0bbfbe 100644 --- a/pdns/threadname.cc +++ b/pdns/threadname.cc @@ -39,7 +39,7 @@ #include "threadname.hh" -void setThreadName(const std::string& threadName) { +int trySetThreadName(const std::string& threadName) { int retval = 0; #ifdef HAVE_PTHREAD_SETNAME_NP_2 @@ -58,6 +58,16 @@ void setThreadName(const std::string& threadName) { retval = pthread_setname_np(pthread_self(), threadName.c_str(), nullptr); #endif + return retval; +} + +void setThreadName(const std::string& threadName) { + int retval = trySetThreadName(threadName); + if (retval == ERANGE) { + const std::string shortThreadName(threadName.substr(0, 15)); + retval = trySetThreadName(shortThreadName); + } + if (retval != 0) { #ifdef DNSDIST warnlog("Could not set thread name %s for thread: %s", threadName, strerror(retval));