Commit | Line | Data |
---|---|---|
b728d87e MD |
1 | #ifndef _UST_COMPAT_H |
2 | #define _UST_COMPAT_H | |
3 | ||
4 | /* | |
e92f3e28 | 5 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
01f0e40c | 6 | * Copyright (C) 2016 Raphaël Beamonte <raphael.beamonte@gmail.com> |
b728d87e | 7 | * |
e92f3e28 MD |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; only | |
11 | * version 2.1 of the License. | |
b728d87e | 12 | * |
e92f3e28 MD |
13 | * This library is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * Lesser General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU Lesser General Public | |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
b728d87e MD |
21 | */ |
22 | ||
d9c56a93 MJ |
23 | #include <pthread.h> |
24 | ||
08114193 | 25 | /* |
d9c56a93 | 26 | * Limit imposed by Linux UST-sessiond ABI. |
08114193 | 27 | */ |
d9c56a93 | 28 | #define LTTNG_UST_PROCNAME_LEN 17 |
08114193 | 29 | |
d9c56a93 | 30 | #define LTTNG_UST_PROCNAME_SUFFIX "-ust" |
08114193 | 31 | |
08114193 | 32 | |
d9c56a93 | 33 | #if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID) |
08114193 | 34 | static inline |
d9c56a93 | 35 | int lttng_pthread_setname_np(const char *name) |
08114193 | 36 | { |
d9c56a93 | 37 | return pthread_setname_np(pthread_self(), name); |
08114193 MD |
38 | } |
39 | ||
01f0e40c | 40 | static inline |
d9c56a93 | 41 | int lttng_pthread_getname_np(char *name, size_t len) |
01f0e40c | 42 | { |
d9c56a93 | 43 | return pthread_getname_np(pthread_self(), name, len); |
01f0e40c | 44 | } |
d9c56a93 | 45 | #elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID) |
e4486ebc | 46 | static inline |
d9c56a93 | 47 | int lttng_pthread_setname_np(const char *name) |
e4486ebc | 48 | { |
d9c56a93 | 49 | return pthread_setname_np(name); |
e4486ebc | 50 | } |
08114193 | 51 | |
d9c56a93 MJ |
52 | static inline |
53 | int lttng_pthread_getname_np(char *name, size_t len) | |
54 | { | |
55 | return pthread_getname_np(name, len); | |
56 | } | |
57 | #else | |
01f0e40c | 58 | /* |
d9c56a93 | 59 | * For platforms without thread name support, do nothing. |
01f0e40c | 60 | */ |
01f0e40c | 61 | static inline |
d9c56a93 | 62 | int lttng_pthread_setname_np(const char *name) |
01f0e40c | 63 | { |
d9c56a93 | 64 | return -ENOSYS; |
01f0e40c | 65 | } |
01f0e40c | 66 | |
d9c56a93 MJ |
67 | static inline |
68 | int lttng_pthread_getname_np(char *name, size_t len) | |
69 | { | |
70 | return -ENOSYS; | |
71 | } | |
01f0e40c RB |
72 | #endif |
73 | ||
d9c56a93 MJ |
74 | static inline |
75 | void lttng_ust_getprocname(char *name) | |
76 | { | |
77 | lttng_pthread_getname_np(name, LTTNG_UST_PROCNAME_LEN); | |
78 | } | |
01f0e40c RB |
79 | |
80 | static inline | |
81 | int lttng_ust_setustprocname(void) | |
82 | { | |
83 | int ret = 0, len; | |
84 | char name[LTTNG_UST_PROCNAME_LEN]; | |
ffaea233 | 85 | int limit = LTTNG_UST_PROCNAME_LEN - strlen(LTTNG_UST_PROCNAME_SUFFIX) - 1; |
01f0e40c | 86 | |
d9c56a93 | 87 | lttng_pthread_getname_np(name, LTTNG_UST_PROCNAME_LEN); |
01f0e40c RB |
88 | |
89 | len = strlen(name); | |
90 | if (len > limit) { | |
91 | len = limit; | |
92 | } | |
93 | ||
94 | ret = sprintf(name + len, LTTNG_UST_PROCNAME_SUFFIX); | |
8db078dc | 95 | if (ret != strlen(LTTNG_UST_PROCNAME_SUFFIX)) { |
01f0e40c RB |
96 | goto error; |
97 | } | |
98 | ||
d9c56a93 | 99 | ret = lttng_pthread_setname_np(name); |
01f0e40c RB |
100 | |
101 | error: | |
102 | return ret; | |
103 | } | |
d9c56a93 | 104 | |
08114193 | 105 | |
bdcf8d82 MD |
106 | #include <errno.h> |
107 | ||
108 | #ifndef ENODATA | |
109 | #define ENODATA ENOMSG | |
110 | #endif | |
111 | ||
b728d87e | 112 | #endif /* _UST_COMPAT_H */ |