5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Copyright (C) 2016 Raphaƫl Beamonte <raphael.beamonte@gmail.com>
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.
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.
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
24 * lttng_ust_getprocname.
28 #include <sys/prctl.h>
30 #define LTTNG_UST_PROCNAME_LEN 17
33 void lttng_ust_getprocname(char *name
)
35 (void) prctl(PR_GET_NAME
, (unsigned long) name
, 0, 0, 0);
39 * If pthread_setname_np is available.
41 #ifdef HAVE_PTHREAD_SETNAME_NP
43 int lttng_pthread_setname_np(pthread_t thread
, const char *name
)
45 return pthread_setname_np(thread
, name
);
49 #elif defined(__FreeBSD__)
55 * Limit imposed by Linux UST-sessiond ABI.
57 #define LTTNG_UST_PROCNAME_LEN 17
60 * Acts like linux prctl, the string is not necessarily 0-terminated if
64 void lttng_ust_getprocname(char *name
)
68 bsd_name
= getprogname();
72 strncpy(name
, bsd_name
, LTTNG_UST_PROCNAME_LEN
- 1);
76 * If pthread_set_name_np is available.
78 #ifdef HAVE_PTHREAD_SET_NAME_NP
80 int lttng_pthread_setname_np(pthread_t thread
, const char *name
)
82 return pthread_set_name_np(thread
, name
);
89 * If a pthread setname/set_name function is available, declare
90 * the setustprocname() function that will add '-ust' to the end
91 * of the current process name, while truncating it if needed.
93 #if defined(HAVE_PTHREAD_SETNAME_NP) || defined(HAVE_PTHREAD_SETNAME_NP)
94 #define LTTNG_UST_PROCNAME_SUFFIX "-ust"
99 int lttng_ust_setustprocname(void)
102 char name
[LTTNG_UST_PROCNAME_LEN
];
103 int limit
= LTTNG_UST_PROCNAME_LEN
- strlen(LTTNG_UST_PROCNAME_SUFFIX
) - 1;
105 lttng_ust_getprocname(name
);
112 ret
= sprintf(name
+ len
, LTTNG_UST_PROCNAME_SUFFIX
);
113 if (ret
!= strlen(LTTNG_UST_PROCNAME_SUFFIX
)) {
117 ret
= lttng_pthread_setname_np(pthread_self(), name
);
124 int lttng_ust_setustprocname(void)
133 #define ENODATA ENOMSG
136 #endif /* _UST_COMPAT_H */