summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
fb54def)
The detection was broken and initialy went undetected because of the
failover code. Replace it with a hard fail and fix the detection for
each platform.
Also, replace the private LTTNG_UST_PROCNAME_LEN with
LTTNG_UST_ABI_PROCNAME_LEN from the public headers. The limit of 16
bytes does in fact include the terminating null byte contrary to what
was defined in LTTNG_UST_PROCNAME_LEN. This was not catched before since
the string is silently truncated if it exceeds 16 bytes.
Change-Id: I1ea95dfd882dfeb80fdc3d71ebec6618b1324a79
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
reg_msg.uint64_t_alignment = uint64_t_alignment;
reg_msg.long_alignment = long_alignment;
reg_msg.socket_type = type;
reg_msg.uint64_t_alignment = uint64_t_alignment;
reg_msg.long_alignment = long_alignment;
reg_msg.socket_type = type;
- lttng_ust_getprocname(reg_msg.name);
+ lttng_pthread_getname_np(reg_msg.name, LTTNG_UST_ABI_PROCNAME_LEN);
memset(reg_msg.padding, 0, sizeof(reg_msg.padding));
len = ustcomm_send_unix_sock(sock, ®_msg, sizeof(reg_msg));
memset(reg_msg.padding, 0, sizeof(reg_msg.padding));
len = ustcomm_send_unix_sock(sock, ®_msg, sizeof(reg_msg));
/*
* Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
* Copyright (C) 2016 Raphaël Beamonte <raphael.beamonte@gmail.com>
/*
* Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
* Copyright (C) 2016 Raphaël Beamonte <raphael.beamonte@gmail.com>
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
-/*
- * Limit imposed by Linux UST-sessiond ABI.
- */
-#define LTTNG_UST_PROCNAME_LEN 17
+#include <lttng/ust-abi.h>
#define LTTNG_UST_PROCNAME_SUFFIX "-ust"
#define LTTNG_UST_PROCNAME_SUFFIX "-ust"
static inline
int lttng_pthread_setname_np(const char *name)
{
static inline
int lttng_pthread_setname_np(const char *name)
{
- return pthread_setname_np(pthread_self(), name);
+ return pthread_setname_np(pthread_self(), name);
}
static inline
int lttng_pthread_getname_np(char *name, size_t len)
{
}
static inline
int lttng_pthread_getname_np(char *name, size_t len)
{
- return pthread_getname_np(pthread_self(), name, len);
+ return pthread_getname_np(pthread_self(), name, len);
}
#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
static inline
int lttng_pthread_setname_np(const char *name)
{
}
#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
static inline
int lttng_pthread_setname_np(const char *name)
{
- return pthread_setname_np(name);
+ return pthread_setname_np(name);
}
static inline
int lttng_pthread_getname_np(char *name, size_t len)
{
}
static inline
int lttng_pthread_getname_np(char *name, size_t len)
{
- return pthread_getname_np(name, len);
+ return pthread_getname_np(name, len);
-#else
-/*
- * For platforms without thread name support, do nothing.
- */
+#elif defined(HAVE_PTHREAD_SET_NAME_NP_WITH_TID)
+
+#include <pthread_np.h>
static inline
int lttng_pthread_setname_np(const char *name)
{
static inline
int lttng_pthread_setname_np(const char *name)
{
+ pthread_set_name_np(pthread_self(), name);
+ return 0;
}
static inline
int lttng_pthread_getname_np(char *name, size_t len)
{
}
static inline
int lttng_pthread_getname_np(char *name, size_t len)
{
+ pthread_get_name_np(pthread_self(), name, len);
+ return 0;
+}
+#elif defined(__linux__)
+
+/* Fallback on prtctl on Linux */
+#include <sys/prctl.h>
+
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+ return prctl(PR_SET_NAME, name, 0, 0, 0);
-void lttng_ust_getprocname(char *name)
+int lttng_pthread_getname_np(char *name, size_t len)
- lttng_pthread_getname_np(name, LTTNG_UST_PROCNAME_LEN);
+ return prctl(PR_GET_NAME, name, 0, 0, 0);
+#else
+#error "Please add pthread name support for your OS."
+#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.
+ */
static inline
int lttng_ust_setustprocname(void)
{
int ret = 0, len;
static inline
int lttng_ust_setustprocname(void)
{
int ret = 0, len;
- char name[LTTNG_UST_PROCNAME_LEN];
- int limit = LTTNG_UST_PROCNAME_LEN - strlen(LTTNG_UST_PROCNAME_SUFFIX) - 1;
-
- lttng_pthread_getname_np(name, LTTNG_UST_PROCNAME_LEN);
+ char name[LTTNG_UST_ABI_PROCNAME_LEN];
+ int limit = LTTNG_UST_ABI_PROCNAME_LEN - strlen(LTTNG_UST_PROCNAME_SUFFIX) - 1;
+
+ /*
+ * Get the current thread name.
+ */
+ ret = lttng_pthread_getname_np(name, LTTNG_UST_ABI_PROCNAME_LEN);
+ if (ret) {
+ goto error;
+ }
len = strlen(name);
if (len > limit) {
len = strlen(name);
if (len > limit) {
#include <errno.h>
#ifndef ENODATA
#include <errno.h>
#ifndef ENODATA
CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting + 1);
/* Increment nesting before updating cache. */
cmm_barrier();
CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting + 1);
/* Increment nesting before updating cache. */
cmm_barrier();
- lttng_ust_getprocname(URCU_TLS(cached_procname)[nesting]);
- URCU_TLS(cached_procname)[nesting][LTTNG_UST_PROCNAME_LEN - 1] = '\0';
+ lttng_pthread_getname_np(URCU_TLS(cached_procname)[nesting], LTTNG_UST_ABI_PROCNAME_LEN);
+ URCU_TLS(cached_procname)[nesting][LTTNG_UST_ABI_PROCNAME_LEN - 1] = '\0';
/* Decrement nesting after updating cache. */
cmm_barrier();
CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting);
/* Decrement nesting after updating cache. */
cmm_barrier();
CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting);
static
size_t procname_get_size(struct lttng_ctx_field *field, size_t offset)
{
static
size_t procname_get_size(struct lttng_ctx_field *field, size_t offset)
{
- return LTTNG_UST_PROCNAME_LEN;
+ return LTTNG_UST_ABI_PROCNAME_LEN;
char *procname;
procname = wrapper_getprocname();
char *procname;
procname = wrapper_getprocname();
- chan->ops->event_write(ctx, procname, LTTNG_UST_PROCNAME_LEN);
+ chan->ops->event_write(ctx, procname, LTTNG_UST_ABI_PROCNAME_LEN);
field->event_field.type.atype = atype_array_nestable;
field->event_field.type.u.array_nestable.elem_type =
&procname_array_elem_type;
field->event_field.type.atype = atype_array_nestable;
field->event_field.type.u.array_nestable.elem_type =
&procname_array_elem_type;
- field->event_field.type.u.array_nestable.length = LTTNG_UST_PROCNAME_LEN;
+ field->event_field.type.u.array_nestable.length = LTTNG_UST_ABI_PROCNAME_LEN;
field->get_size = procname_get_size;
field->record = procname_record;
field->get_value = procname_get_value;
field->get_size = procname_get_size;
field->record = procname_record;
field->get_value = procname_get_value;
int statedump_pending;
int initial_statedump_done;
/* Keep procname for statedump */
int statedump_pending;
int initial_statedump_done;
/* Keep procname for statedump */
- char procname[LTTNG_UST_PROCNAME_LEN];
+ char procname[LTTNG_UST_ABI_PROCNAME_LEN];
};
/* Socket from app (connect) to session daemon (listen) for communication */
};
/* Socket from app (connect) to session daemon (listen) for communication */
}
global_apps.allowed = 1;
}
global_apps.allowed = 1;
- lttng_ust_getprocname(global_apps.procname);
+ lttng_pthread_getname_np(global_apps.procname, LTTNG_UST_ABI_PROCNAME_LEN);
- lttng_ust_getprocname(local_apps.procname);
+ lttng_pthread_getname_np(local_apps.procname, LTTNG_UST_ABI_PROCNAME_LEN);
char *, name
),
TP_FIELDS(
char *, name
),
TP_FIELDS(
- ctf_array_text(char, procname, name, LTTNG_UST_PROCNAME_LEN)
+ ctf_array_text(char, procname, name, LTTNG_UST_ABI_PROCNAME_LEN)
[Have function pthread_setname_np(const char*)])],
[AC_MSG_RESULT(no)])
[Have function pthread_setname_np(const char*)])],
[AC_MSG_RESULT(no)])
+# FreeBSD
+AC_MSG_CHECKING(for pthread_set_name_np(pthread_t, const char*))
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [#include <pthread.h>
+ #include <pthread_np.h>],
+ [pthread_set_name_np(pthread_self(), "example")])],
+ [AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP_WITH_TID,1,
+ [Have function pthread_set_name_np(pthread_t, const char*)])],
+ [AC_MSG_RESULT(no)])
+
LDFLAGS=$lttng_pthread_setname_np_save_LDFLAGS
LIBS=$lttng_pthread_setname_np_save_LIBS
LDFLAGS=$lttng_pthread_setname_np_save_LDFLAGS
LIBS=$lttng_pthread_setname_np_save_LIBS