summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSongtao Zhan <zhanst1@chinatelecom.cn>2023-04-19 09:38:52 +0800
committerIlya Maximets <i.maximets@ovn.org>2023-04-25 21:54:47 +0200
commit3fa0fc5824324c11d78bf961648bb200da31d7bd (patch)
tree2e9297b468ce6cc287fc5614d73d60ac06eedadd
parent36c8c101cdcd668afefee94f3c0f62ef0bc6d286 (diff)
downloadopenvswitch-3fa0fc5824324c11d78bf961648bb200da31d7bd.tar.gz
util: Fix an issue that thread name cannot be set.
The name of the current thread consists of a name with a maximum length of 16 bytes and a thread ID. The final name may be longer than 16 bytes. If the name is longer than 16 bytes, the thread name will fail to be set Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Songtao Zhan <zhanst1@chinatelecom.cn> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rw-r--r--lib/util.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/util.c b/lib/util.c
index 96a71550d..3fb3a4b40 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -645,6 +645,12 @@ set_subprogram_name(const char *subprogram_name)
free(subprogram_name_set(pname));
#if HAVE_GLIBC_PTHREAD_SETNAME_NP
+ /* The maximum supported thread name including '\0' is 16.
+ * Add '>' at 0th position to highlight that the name was truncated. */
+ if (strlen(pname) > 15) {
+ memmove(pname, &pname[strlen(pname) - 15], 15 + 1);
+ pname[0] = '>';
+ }
pthread_setname_np(pthread_self(), pname);
#elif HAVE_NETBSD_PTHREAD_SETNAME_NP
pthread_setname_np(pthread_self(), "%s", pname);