X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=src%2Flib%2Flttng-ust%2Flttng-ust-comm.c;h=c84594ba8c69408ce316eb83b3a057a11a6e7cbd;hb=9b14815a9ee98c0dbc842a1e545cd6a82ae7b18a;hp=995c78ff21b32c2c9043e8aa2a2c51cea72cb870;hpb=c6e6343c93e1b6ec02de1f9dc825faae0d6cc7ab;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 995c78ff..c84594ba 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,21 +37,23 @@ #include #include #include +#include #include +#include "common/compat/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" #include "common/ringbuffer/rb-init.h" #include "lttng-ust-statedump.h" #include "clock.h" -#include "common/ringbuffer/getcpu.h" -#include "getenv.h" -#include "ust-events-internal.h" +#include "lib/lttng-ust/getcpu.h" +#include "common/getenv.h" +#include "lib/lttng-ust/events.h" #include "context-internal.h" #include "common/align.h" #include "lttng-counter-client.h" @@ -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. @@ -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; @@ -2120,12 +2103,23 @@ 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_init(); + lttng_ust_getcpu_plugin_init(); lttng_ust_statedump_init(); lttng_ust_ring_buffer_clients_init(); lttng_ust_counter_clients_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); @@ -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)