From 62014aeccde2dac680276a6ea3d6d5cca75e43a3 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 21 May 2021 13:41:40 -0700 Subject: [PATCH] util/u_thread: fix u_thread_setname for long names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "WSI swapchain queue", set by vulkan/wsi/x11, is longer than 15 characters. Signed-off-by: Chia-I Wu Reviewed-by: Marek Olšák Part-of: --- src/util/u_thread.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util/u_thread.h b/src/util/u_thread.h index 8366bfb6d49..5fd2fe502ee 100644 --- a/src/util/u_thread.h +++ b/src/util/u_thread.h @@ -27,6 +27,7 @@ #ifndef U_THREAD_H_ #define U_THREAD_H_ +#include #include #include #include @@ -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