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 <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
#include <pthread.h>
#include <errno.h>
+#include <string.h>
#include <lttng/ust-abi.h>
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;
}
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);
}