From f2db7517e508d970c8a5bebfb05334dc5ee72b87 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Fri, 16 Oct 2020 15:44:36 -0400 Subject: [PATCH] fix: pthread_setname_np fails on longer tread names When supplied with a thread name of more than 16 bytes including the null terminating byte pthread_setname_np will fail with ERANGE, replicate this behavior in the compat wrappers. Change-Id: I91ac35a400a39c297e49fcab83b4f345b7ad92d0 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- liblttng-ust/compat.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/liblttng-ust/compat.h b/liblttng-ust/compat.h index 69761880..a941b9a1 100644 --- a/liblttng-ust/compat.h +++ b/liblttng-ust/compat.h @@ -23,6 +23,7 @@ #include #include +#include #include @@ -59,6 +60,11 @@ int lttng_pthread_getname_np(char *name, size_t len) static inline int lttng_pthread_setname_np(const char *name) { + /* Replicate pthread_setname_np's behavior */ + if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) { + return ERANGE; + } + pthread_set_name_np(pthread_self(), name); return 0; } @@ -77,6 +83,10 @@ int lttng_pthread_getname_np(char *name, size_t len) static inline int lttng_pthread_setname_np(const char *name) { + /* Replicate pthread_setname_np's behavior */ + if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) { + return ERANGE; + } return prctl(PR_SET_NAME, name, 0, 0, 0); } -- 2.34.1