]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Try shorter thread names
authorJosh Soref <jsoref@users.noreply.github.com>
Thu, 30 Dec 2021 03:40:10 +0000 (22:40 -0500)
committerJosh Soref <jsoref@users.noreply.github.com>
Thu, 30 Dec 2021 03:40:10 +0000 (22:40 -0500)
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

index 249248a62387ff54f65cb26862ef11be8bfd1650..35fa0bbfbeca9b8fddf5aa08f739004b97a1a6f3 100644 (file)
@@ -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));