Commit | Line | Data |
---|---|---|
cb8d0d24 MJ |
1 | /* |
2 | * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: LGPL-2.1-only | |
5 | * | |
6 | */ | |
7 | ||
8 | #include <string.h> | |
9 | ||
10 | #include <common/compat/pthread.h> | |
11 | #include "thread.h" | |
12 | ||
13 | #define LTTNG_PTHREAD_NAMELEN 16 | |
14 | ||
15 | int lttng_thread_setname(const char *name) | |
16 | { | |
17 | int ret; | |
18 | char pthread_name[LTTNG_PTHREAD_NAMELEN]; | |
19 | ||
20 | /* | |
21 | * Truncations are expected since pthread limits thread names to | |
22 | * a generous 16 characters. | |
23 | */ | |
24 | strncpy(pthread_name, name, sizeof(pthread_name)); | |
25 | pthread_name[sizeof(pthread_name) - 1] = '\0'; | |
26 | ||
27 | ret = lttng_pthread_setname_np(pthread_name); | |
28 | ||
29 | return ret; | |
30 | } | |
31 |