Cleanup: standardise include path
[lttng-ust.git] / liblttng-ust / compat.h
... / ...
CommitLineData
1#ifndef _UST_COMPAT_H
2#define _UST_COMPAT_H
3
4/*
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Copyright (C) 2016 Raphaƫl Beamonte <raphael.beamonte@gmail.com>
7 *
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.
12 *
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
21 */
22
23#include <pthread.h>
24
25/*
26 * Limit imposed by Linux UST-sessiond ABI.
27 */
28#define LTTNG_UST_PROCNAME_LEN 17
29
30#define LTTNG_UST_PROCNAME_SUFFIX "-ust"
31
32
33#if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID)
34static inline
35int lttng_pthread_setname_np(const char *name)
36{
37 return pthread_setname_np(pthread_self(), name);
38}
39
40static inline
41int lttng_pthread_getname_np(char *name, size_t len)
42{
43 return pthread_getname_np(pthread_self(), name, len);
44}
45#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
46static inline
47int lttng_pthread_setname_np(const char *name)
48{
49 return pthread_setname_np(name);
50}
51
52static inline
53int lttng_pthread_getname_np(char *name, size_t len)
54{
55 return pthread_getname_np(name, len);
56}
57#else
58/*
59 * For platforms without thread name support, do nothing.
60 */
61static inline
62int lttng_pthread_setname_np(const char *name)
63{
64 return -ENOSYS;
65}
66
67static inline
68int lttng_pthread_getname_np(char *name, size_t len)
69{
70 return -ENOSYS;
71}
72#endif
73
74static inline
75void lttng_ust_getprocname(char *name)
76{
77 lttng_pthread_getname_np(name, LTTNG_UST_PROCNAME_LEN);
78}
79
80static inline
81int lttng_ust_setustprocname(void)
82{
83 int ret = 0, len;
84 char name[LTTNG_UST_PROCNAME_LEN];
85 int limit = LTTNG_UST_PROCNAME_LEN - strlen(LTTNG_UST_PROCNAME_SUFFIX) - 1;
86
87 lttng_pthread_getname_np(name, LTTNG_UST_PROCNAME_LEN);
88
89 len = strlen(name);
90 if (len > limit) {
91 len = limit;
92 }
93
94 ret = sprintf(name + len, LTTNG_UST_PROCNAME_SUFFIX);
95 if (ret != strlen(LTTNG_UST_PROCNAME_SUFFIX)) {
96 goto error;
97 }
98
99 ret = lttng_pthread_setname_np(name);
100
101error:
102 return ret;
103}
104
105
106#include <errno.h>
107
108#ifndef ENODATA
109#define ENODATA ENOMSG
110#endif
111
112#endif /* _UST_COMPAT_H */
This page took 0.022552 seconds and 4 git commands to generate.