From f3813e097ef9b4053009372e8009915bcd496a63 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Wed, 29 Dec 2021 22:40:10 -0500 Subject: [PATCH] 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'). --- pdns/threadname.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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)); -- 2.47.2