From: Mathieu Desnoyers Date: Wed, 28 Sep 2011 00:39:07 +0000 (-0400) Subject: Reset vtid after fork in child X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a93bfc45c7cc2117d27f69eb420ab3333280e026;p=ust.git Reset vtid after fork in child Signed-off-by: Mathieu Desnoyers --- diff --git a/include/ust/lttng-events.h b/include/ust/lttng-events.h index 7a8cf6f..6bb4e8c 100644 --- a/include/ust/lttng-events.h +++ b/include/ust/lttng-events.h @@ -322,5 +322,6 @@ void lttng_remove_context_field(struct lttng_ctx **ctx_p, void lttng_destroy_context(struct lttng_ctx *ctx); int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx); +void lttng_context_vtid_reset(void); #endif /* _UST_LTTNG_EVENTS_H */ diff --git a/libust/lttng-context-vtid.c b/libust/lttng-context-vtid.c index fd1e320..a7e1c81 100644 --- a/libust/lttng-context-vtid.c +++ b/libust/lttng-context-vtid.c @@ -38,6 +38,16 @@ static inline pid_t gettid(void) */ static __thread pid_t cached_vtid; +/* + * Upon fork or clone, the TID assigned to our thread is not the same as + * we kept in cache. Luckily, we are the only thread surviving in the + * child process, so we can simply clear our cached version. + */ +void lttng_context_vtid_reset(void) +{ + cached_vtid = 0; +} + static size_t vtid_get_size(size_t offset) { diff --git a/libust/lttng-ust-comm.c b/libust/lttng-ust-comm.c index 6bf9e2b..7971168 100644 --- a/libust/lttng-ust-comm.c +++ b/libust/lttng-ust-comm.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -924,6 +925,7 @@ void ust_after_fork_child(ust_fork_info_t *fork_info) /* Release urcu mutexes */ rcu_bp_after_fork_child(); lttng_ust_cleanup(0); + lttng_context_vtid_reset(); /* Release mutexes and reenable signals */ ust_after_fork_common(fork_info); lttng_ust_init();