X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust%2Fcompat.h;h=7d1ee590326fd1b9616569420b32846d4e458f7f;hb=d9c56a93651a409c6ceea65ed1d7f33e3f5ee538;hp=003b480aa01d27dc428877dc9935963335e5340d;hpb=222fa4532b6f8c0f0be4e3781a16a90efbd52a59;p=lttng-ust.git diff --git a/liblttng-ust/compat.h b/liblttng-ust/compat.h index 003b480a..7d1ee590 100644 --- a/liblttng-ust/compat.h +++ b/liblttng-ust/compat.h @@ -20,80 +20,62 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + /* - * lttng_ust_getprocname. + * Limit imposed by Linux UST-sessiond ABI. */ -#ifdef __linux__ +#define LTTNG_UST_PROCNAME_LEN 17 -#include +#define LTTNG_UST_PROCNAME_SUFFIX "-ust" -#define LTTNG_UST_PROCNAME_LEN 17 +#if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID) static inline -void lttng_ust_getprocname(char *name) +int lttng_pthread_setname_np(const char *name) { - (void) prctl(PR_GET_NAME, (unsigned long) name, 0, 0, 0); + return pthread_setname_np(pthread_self(), name); } -/* - * If pthread_setname_np is available. - */ -#ifdef HAVE_PTHREAD_SETNAME_NP static inline -int lttng_pthread_setname_np(pthread_t thread, const char *name) +int lttng_pthread_getname_np(char *name, size_t len) { - return pthread_setname_np(thread, name); + return pthread_getname_np(pthread_self(), name, len); } -#endif - -#elif defined(__FreeBSD__) - -#include -#include - -/* - * Limit imposed by Linux UST-sessiond ABI. - */ -#define LTTNG_UST_PROCNAME_LEN 17 - -/* - * Acts like linux prctl, the string is not necessarily 0-terminated if - * 16-byte long. - */ +#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID) static inline -void lttng_ust_getprocname(char *name) +int lttng_pthread_setname_np(const char *name) { - const char *bsd_name; - - bsd_name = getprogname(); - if (!bsd_name) - name[0] = '\0'; - else - strncpy(name, bsd_name, LTTNG_UST_PROCNAME_LEN - 1); + return pthread_setname_np(name); } +static inline +int lttng_pthread_getname_np(char *name, size_t len) +{ + return pthread_getname_np(name, len); +} +#else /* - * If pthread_set_name_np is available. + * For platforms without thread name support, do nothing. */ -#ifdef HAVE_PTHREAD_SET_NAME_NP static inline -int lttng_pthread_setname_np(pthread_t thread, const char *name) +int lttng_pthread_setname_np(const char *name) { - return pthread_set_name_np(thread, name); + return -ENOSYS; } -#endif +static inline +int lttng_pthread_getname_np(char *name, size_t len) +{ + return -ENOSYS; +} #endif -/* - * If a pthread setname/set_name function is available, declare - * the setustprocname() function that will add '-ust' to the end - * of the current process name, while truncating it if needed. - */ -#if defined(HAVE_PTHREAD_SETNAME_NP) || defined(HAVE_PTHREAD_SETNAME_NP) -#define LTTNG_UST_PROCNAME_SUFFIX "-ust" - -#include +static inline +void lttng_ust_getprocname(char *name) +{ + lttng_pthread_getname_np(name, LTTNG_UST_PROCNAME_LEN); +} static inline int lttng_ust_setustprocname(void) @@ -102,7 +84,7 @@ int lttng_ust_setustprocname(void) char name[LTTNG_UST_PROCNAME_LEN]; int limit = LTTNG_UST_PROCNAME_LEN - strlen(LTTNG_UST_PROCNAME_SUFFIX) - 1; - lttng_ust_getprocname(name); + lttng_pthread_getname_np(name, LTTNG_UST_PROCNAME_LEN); len = strlen(name); if (len > limit) { @@ -114,18 +96,12 @@ int lttng_ust_setustprocname(void) goto error; } - ret = lttng_pthread_setname_np(pthread_self(), name); + ret = lttng_pthread_setname_np(name); error: return ret; } -#else -static inline -int lttng_ust_setustprocname(void) -{ - return 0; -} -#endif + #include