From: Mathieu Desnoyers Date: Wed, 24 Oct 2012 13:04:14 +0000 (-0400) Subject: Fix: procname context semantic X-Git-Tag: v2.1.0-rc2~25 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=009745db8ca05f7a3abbb37558b08eae0107f7e1;p=lttng-ust.git Fix: procname context semantic Cache the procname per-thread rather than per-process to take into account that prctl() can be used to set thread names. prctl() should be issued before tracing each thread's first event if we care about the thread name. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/ltt-tracer-core.h b/liblttng-ust/ltt-tracer-core.h index 2ea4eadf..34c5557a 100644 --- a/liblttng-ust/ltt-tracer-core.h +++ b/liblttng-ust/ltt-tracer-core.h @@ -39,5 +39,6 @@ void ust_unlock(void); void lttng_fixup_event_tls(void); void lttng_fixup_vtid_tls(void); +void lttng_fixup_procname_tls(void); #endif /* _LTT_TRACER_CORE_H */ diff --git a/liblttng-ust/lttng-context-procname.c b/liblttng-ust/lttng-context-procname.c index d165be88..96cd1ee2 100644 --- a/liblttng-ust/lttng-context-procname.c +++ b/liblttng-ust/lttng-context-procname.c @@ -3,7 +3,7 @@ * * LTTng UST procname context. * - * Copyright (C) 2009-2011 Mathieu Desnoyers + * Copyright (C) 2009-2012 Mathieu Desnoyers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,8 +31,11 @@ * each event. * Upon exec, procname changes, but exec takes care of throwing away * this cached version. + * The procname can also change by calling prctl(). The procname should + * be set for a thread before the first event is logged within this + * thread. */ -static char cached_procname[17]; +static __thread char cached_procname[17]; static inline char *wrapper_getprocname(void) @@ -94,3 +97,11 @@ int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) field->record = procname_record; return 0; } + +/* + * Force a read (imply TLS fixup for dlopen) of TLS variables. + */ +void lttng_fixup_procname_tls(void) +{ + asm volatile ("" : : "m" (cached_procname[0])); +} diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index efc6724f..31955bb5 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -952,6 +952,7 @@ void __attribute__((constructor)) lttng_ust_init(void) lttng_fixup_ringbuffer_tls(); lttng_fixup_vtid_tls(); lttng_fixup_nest_count_tls(); + lttng_fixup_procname_tls(); /* * We want precise control over the order in which we construct