From: Michael Jeanson Date: Fri, 16 Oct 2020 19:44:36 +0000 (-0400) Subject: fix: pthread_setname_np fails on longer tread names X-Git-Tag: v2.13.0-rc1~474 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f2db7517e508d970c8a5bebfb05334dc5ee72b87;p=lttng-ust.git 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 --- 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); }