util/u_thread: fix u_thread_setname for long names
authorChia-I Wu <olvaffe@gmail.com>
Fri, 21 May 2021 20:41:40 +0000 (13:41 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 25 May 2021 16:39:02 +0000 (16:39 +0000)
"WSI swapchain queue", set by vulkan/wsi/x11, is longer than 15
characters.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10935>

src/util/u_thread.h

index 8366bfb..5fd2fe5 100644 (file)
@@ -27,6 +27,7 @@
 #ifndef U_THREAD_H_
 #define U_THREAD_H_
 
+#include <errno.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <string.h>
@@ -104,7 +105,14 @@ static inline void u_thread_setname( const char *name )
 {
 #if defined(HAVE_PTHREAD)
 #if DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS
-   pthread_setname_np(pthread_self(), name);
+   int ret = pthread_setname_np(pthread_self(), name);
+   if (ret == ERANGE) {
+      char buf[16];
+      const size_t len = MIN2(strlen(name), ARRAY_SIZE(buf) - 1);
+      memcpy(buf, name, len);
+      buf[len] = '\0';
+      pthread_setname_np(pthread_self(), buf);
+   }
 #elif DETECT_OS_FREEBSD || DETECT_OS_OPENBSD
    pthread_set_name_np(pthread_self(), name);
 #elif DETECT_OS_NETBSD