#include "threadname.hh"
-void setThreadName(const std::string& threadName) {
+int trySetThreadName(const std::string& threadName) {
int retval = 0;
#ifdef HAVE_PTHREAD_SETNAME_NP_2
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));