X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Flib%2Flttng-ust%2Flttng-ust-comm.c;h=61f0b34adc9d634113119ddf323a8b056aff8bde;hb=08ba2503b86d1506117c077c99eb1c38973a48f3;hp=2f6fe18faefa2a604e594ef0e487a7dee5bdc376;hpb=910dcd720731c190adbfb9bb50c67bb9c4235003;p=lttng-ust.git diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index 2f6fe18f..61f0b34a 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -25,7 +25,6 @@ #include #include #include -#include "futex.h" #include #include @@ -38,12 +37,14 @@ #include #include #include +#include #include +#include "lib/lttng-ust/futex.h" #include "common/ustcomm.h" #include "common/ust-fd.h" #include "common/logging.h" #include "common/macros.h" -#include "tracepoint-internal.h" +#include "common/tracepoint.h" #include "lttng-tracer-core.h" #include "common/compat/pthread.h" #include "common/procname.h" @@ -52,7 +53,7 @@ #include "clock.h" #include "lib/lttng-ust/getcpu.h" #include "common/getenv.h" -#include "ust-events-internal.h" +#include "lib/lttng-ust/events.h" #include "context-internal.h" #include "common/align.h" #include "lttng-counter-client.h" @@ -263,7 +264,7 @@ struct sock_info { }; /* Socket from app (connect) to session daemon (listen) for communication */ -struct sock_info global_apps = { +static struct sock_info global_apps = { .name = "global", .global = 1, @@ -285,7 +286,7 @@ struct sock_info global_apps = { /* TODO: allow global_apps_sock_path override */ -struct sock_info local_apps = { +static struct sock_info local_apps = { .name = "local", .global = 0, .root_handle = -1, @@ -356,24 +357,6 @@ static int got_timeout_env; static char *get_map_shm(struct sock_info *sock_info); -ssize_t lttng_ust_read(int fd, void *buf, size_t len) -{ - ssize_t ret; - size_t copied = 0, to_copy = len; - - do { - ret = read(fd, buf + copied, to_copy); - if (ret > 0) { - copied += ret; - to_copy -= ret; - } - } while ((ret > 0 && to_copy > 0) - || (ret < 0 && errno == EINTR)); - if (ret > 0) { - ret = copied; - } - return ret; -} /* * Returns the HOME directory path. Caller MUST NOT free(3) the returned * pointer. @@ -391,48 +374,48 @@ const char *get_lttng_home_dir(void) } /* - * Force a read (imply TLS fixup for dlopen) of TLS variables. + * Force a read (imply TLS allocation for dlopen) of TLS variables. */ static -void lttng_fixup_nest_count_tls(void) +void lttng_nest_count_alloc_tls(void) { asm volatile ("" : : "m" (URCU_TLS(lttng_ust_nest_count))); } static -void lttng_fixup_ust_mutex_nest_tls(void) +void lttng_ust_mutex_nest_alloc_tls(void) { asm volatile ("" : : "m" (URCU_TLS(ust_mutex_nest))); } /* - * Fixup lttng-ust urcu TLS. + * Allocate lttng-ust urcu TLS. */ static -void lttng_fixup_lttng_ust_urcu_tls(void) +void lttng_lttng_ust_urcu_alloc_tls(void) { (void) lttng_ust_urcu_read_ongoing(); } -void lttng_ust_fixup_tls(void) +void lttng_ust_alloc_tls(void) { - lttng_fixup_lttng_ust_urcu_tls(); - lttng_fixup_ringbuffer_tls(); - lttng_fixup_vtid_tls(); - lttng_fixup_nest_count_tls(); - lttng_fixup_procname_tls(); - lttng_fixup_ust_mutex_nest_tls(); - lttng_ust_fixup_perf_counter_tls(); - lttng_ust_fixup_fd_tracker_tls(); - lttng_fixup_cgroup_ns_tls(); - lttng_fixup_ipc_ns_tls(); - lttng_fixup_net_ns_tls(); - lttng_fixup_time_ns_tls(); - lttng_fixup_uts_ns_tls(); - lttng_ust_fixup_ring_buffer_client_discard_tls(); - lttng_ust_fixup_ring_buffer_client_discard_rt_tls(); - lttng_ust_fixup_ring_buffer_client_overwrite_tls(); - lttng_ust_fixup_ring_buffer_client_overwrite_rt_tls(); + lttng_lttng_ust_urcu_alloc_tls(); + lttng_ringbuffer_alloc_tls(); + lttng_vtid_alloc_tls(); + lttng_nest_count_alloc_tls(); + lttng_procname_alloc_tls(); + lttng_ust_mutex_nest_alloc_tls(); + lttng_ust_perf_counter_alloc_tls(); + lttng_ust_common_alloc_tls(); + lttng_cgroup_ns_alloc_tls(); + lttng_ipc_ns_alloc_tls(); + lttng_net_ns_alloc_tls(); + lttng_time_ns_alloc_tls(); + lttng_uts_ns_alloc_tls(); + lttng_ust_ring_buffer_client_discard_alloc_tls(); + lttng_ust_ring_buffer_client_discard_rt_alloc_tls(); + lttng_ust_ring_buffer_client_overwrite_alloc_tls(); + lttng_ust_ring_buffer_client_overwrite_rt_alloc_tls(); } /* @@ -453,7 +436,7 @@ void lttng_ust_init_thread(void) * ensure those are initialized before a signal handler nesting over * this thread attempts to use them. */ - lttng_ust_fixup_tls(); + lttng_ust_alloc_tls(); } int lttng_get_notify_socket(void *owner) @@ -638,7 +621,7 @@ void get_allow_blocking(void) } static -int register_to_sessiond(int socket, enum ustctl_socket_type type) +int register_to_sessiond(int socket, enum lttng_ust_ctl_socket_type type) { return ustcomm_send_reg_msg(socket, type, @@ -1758,7 +1741,7 @@ void *ust_listener_thread(void *arg) int sock, ret, prev_connect_failed = 0, has_waited = 0, fd; long timeout; - lttng_ust_fixup_tls(); + lttng_ust_alloc_tls(); /* * If available, add '-ust' to the end of this thread's * process name @@ -1876,7 +1859,7 @@ restart: sock_info->root_handle = ret; } - ret = register_to_sessiond(sock_info->socket, USTCTL_SOCKET_CMD); + ret = register_to_sessiond(sock_info->socket, LTTNG_UST_CTL_SOCKET_CMD); if (ret < 0) { ERR("Error registering to %s ust cmd socket", sock_info->name); @@ -1969,7 +1952,7 @@ restart: } ret = register_to_sessiond(sock_info->notify_socket, - USTCTL_SOCKET_NOTIFY); + LTTNG_UST_CTL_SOCKET_NOTIFY); if (ret < 0) { ERR("Error registering to %s ust notify socket", sock_info->name); @@ -2061,7 +2044,7 @@ quit: * Weak symbol to call when the ust malloc wrapper is not loaded. */ __attribute__((weak)) -void lttng_ust_libc_wrapper_malloc_init(void) +void lttng_ust_libc_wrapper_malloc_ctor(void) { } @@ -2070,10 +2053,10 @@ void lttng_ust_libc_wrapper_malloc_init(void) * sessiond by polling the application common named pipe. */ static -void lttng_ust_init(void) +void lttng_ust_ctor(void) __attribute__((constructor)); static -void lttng_ust_init(void) +void lttng_ust_ctor(void) { struct timespec constructor_timeout; sigset_t sig_all_blocked, orig_parent_mask; @@ -2086,11 +2069,11 @@ void lttng_ust_init(void) return; /* - * Fixup interdependency between TLS fixup mutex (which happens + * Fixup interdependency between TLS allocation mutex (which happens * to be the dynamic linker mutex) and ust_lock, taken within * the ust lock. */ - lttng_ust_fixup_tls(); + lttng_ust_alloc_tls(); lttng_ust_loaded = 1; @@ -2120,10 +2103,21 @@ void lttng_ust_init(void) * sessiond (otherwise leading to errors when trying to create * sessiond before the init functions are completed). */ + + /* + * Both the logging and getenv lazy-initialization uses getenv() + * internally and thus needs to be explicitly initialized in + * liblttng-ust before we start any threads as an unsuspecting normally + * single threaded application using liblttng-ust could be using + * setenv() which is not thread-safe. + */ lttng_ust_logging_init(); - lttng_ust_getenv_init(); /* Needs lttng_ust_logging_init() to be completed. */ + lttng_ust_getenv_init(); + + /* Call the liblttng-ust-common constructor. */ + lttng_ust_common_ctor(); + lttng_ust_tp_init(); - lttng_ust_init_fd_tracker(); lttng_ust_clock_init(); lttng_ust_getcpu_plugin_init(); lttng_ust_statedump_init(); @@ -2133,7 +2127,7 @@ void lttng_ust_init(void) /* * Invoke ust malloc wrapper init before starting other threads. */ - lttng_ust_libc_wrapper_malloc_init(); + lttng_ust_libc_wrapper_malloc_ctor(); timeout_mode = get_constructor_timeout(&constructor_timeout); @@ -2384,8 +2378,8 @@ void lttng_ust_before_fork(sigset_t *save_sigset) sigset_t all_sigs; int ret; - /* Fixup lttng-ust TLS. */ - lttng_ust_fixup_tls(); + /* Allocate lttng-ust TLS. */ + lttng_ust_alloc_tls(); if (URCU_TLS(lttng_ust_nest_count)) return; @@ -2436,7 +2430,7 @@ void lttng_ust_after_fork_parent(sigset_t *restore_sigset) * After fork, in the child, we need to cleanup all the leftover state, * except the worker thread which already magically disappeared thanks * to the weird Linux fork semantics. After tyding up, we call - * lttng_ust_init() again to start over as a new PID. + * lttng_ust_ctor() again to start over as a new PID. * * This is meant for forks() that have tracing in the child between the * fork and following exec call (if there is any). @@ -2457,7 +2451,7 @@ void lttng_ust_after_fork_child(sigset_t *restore_sigset) lttng_ust_cleanup(0); /* Release mutexes and reenable signals */ ust_after_fork_common(restore_sigset); - lttng_ust_init(); + lttng_ust_ctor(); } void lttng_ust_after_setns(void)