Copyright ownership transfer
[lttng-ust.git] / src / common / procname.h
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * Copyright (C) 2016 Raphaƫl Beamonte <raphael.beamonte@gmail.com>
6 * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
7 */
8
9 #ifndef _UST_COMMON_PROCNAME_H
10 #define _UST_COMMON_PROCNAME_H
11
12 #include <string.h>
13 #include <lttng/ust-abi.h>
14
15 #include "common/compat/pthread.h"
16
17 #define LTTNG_UST_PROCNAME_SUFFIX "-ust"
18
19 /*
20 * If a pthread setname/set_name function is available, declare
21 * the setustprocname() function that will add '-ust' to the end
22 * of the current process name, while truncating it if needed.
23 */
24 static inline
25 int lttng_ust_setustprocname(void)
26 {
27 int ret = 0, len;
28 char name[LTTNG_UST_ABI_PROCNAME_LEN];
29 int limit = LTTNG_UST_ABI_PROCNAME_LEN - strlen(LTTNG_UST_PROCNAME_SUFFIX) - 1;
30
31 /*
32 * Get the current thread name.
33 */
34 ret = lttng_pthread_getname_np(name, LTTNG_UST_ABI_PROCNAME_LEN);
35 if (ret) {
36 goto error;
37 }
38
39 len = strlen(name);
40 if (len > limit) {
41 len = limit;
42 }
43
44 ret = sprintf(name + len, LTTNG_UST_PROCNAME_SUFFIX);
45 if (ret != strlen(LTTNG_UST_PROCNAME_SUFFIX)) {
46 goto error;
47 }
48
49 ret = lttng_pthread_setname_np(name);
50
51 error:
52 return ret;
53 }
54
55 #endif /* _UST_COMMON_PROCNAME_H */
This page took 0.030251 seconds and 4 git commands to generate.