From 8bee41fdbf6c1a1b2eaa435f1d195bdb6312e3c3 Mon Sep 17 00:00:00 2001 From: Helge Norberg Date: Tue, 22 Nov 2016 22:17:33 +0100 Subject: [PATCH] [logging] Simplified code for setting kernel thread name in Linux. --- common/os/linux/signal_handlers.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/common/os/linux/signal_handlers.cpp b/common/os/linux/signal_handlers.cpp index 27d74b6ef..579558a00 100644 --- a/common/os/linux/signal_handlers.cpp +++ b/common/os/linux/signal_handlers.cpp @@ -61,15 +61,12 @@ void ensure_gpf_handler_installed_for_thread( { for_thread.name = thread_description; - if (std::strlen(thread_description) > MAX_LINUX_THREAD_NAME_LEN) - { - char truncated[MAX_LINUX_THREAD_NAME_LEN + 1]; - std::memcpy(truncated, thread_description, MAX_LINUX_THREAD_NAME_LEN); - truncated[MAX_LINUX_THREAD_NAME_LEN] = 0; - pthread_setname_np(pthread_self(), truncated); - } - else - pthread_setname_np(pthread_self(), thread_description); + std::string kernel_thread_name = for_thread.name; + + if (kernel_thread_name.length() > MAX_LINUX_THREAD_NAME_LEN) + kernel_thread_name.resize(MAX_LINUX_THREAD_NAME_LEN); + + pthread_setname_np(pthread_self(), kernel_thread_name.c_str()); } } -- 2.39.2