X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-ust-comm.c;h=0cf5ecd9687536be5fc7794c4bfeb28ed135a11f;hb=101dace0dc164352c81cb347a7a0022aa84eabc6;hp=4a21866358b66a4d9f766abdfd47665e2cffe13d;hpb=6548fca464f68be5ded73be6b9a479daf08e62d6;p=lttng-ust.git diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 4a218663..0cf5ecd9 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,7 @@ #include "tracepoint-internal.h" #include "lttng-tracer-core.h" #include "compat.h" -#include "../libringbuffer/tlsfixup.h" +#include "../libringbuffer/rb-init.h" #include "lttng-ust-statedump.h" #include "clock.h" #include "../libringbuffer/getcpu.h" @@ -365,11 +366,11 @@ const char *get_lttng_home_dir(void) { const char *val; - val = (const char *) lttng_secure_getenv("LTTNG_HOME"); + val = (const char *) lttng_getenv("LTTNG_HOME"); if (val != NULL) { return val; } - return (const char *) lttng_secure_getenv("HOME"); + return (const char *) lttng_getenv("HOME"); } /* @@ -470,7 +471,7 @@ long get_timeout(void) long constructor_delay_ms = LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS; if (!got_timeout_env) { - str_timeout = getenv("LTTNG_UST_REGISTER_TIMEOUT"); + str_timeout = lttng_getenv("LTTNG_UST_REGISTER_TIMEOUT"); got_timeout_env = 1; } if (str_timeout) @@ -533,6 +534,19 @@ int get_constructor_timeout(struct timespec *constructor_timeout) return 1; } +static +void get_allow_blocking(void) +{ + const char *str_allow_blocking = + lttng_getenv("LTTNG_UST_ALLOW_BLOCKING"); + + if (str_allow_blocking) { + DBG("%s environment variable is set", + "LTTNG_UST_ALLOW_BLOCKING"); + lttng_ust_ringbuffer_set_allow_blocking(); + } +} + static int register_to_sessiond(int socket, enum ustctl_socket_type type) { @@ -956,6 +970,21 @@ int handle_message(struct sock_info *sock_info, } } DBG("Return value: %d", lur.ret_val); + + ust_unlock(); + + /* + * Performed delayed statedump operations outside of the UST + * lock. We need to take the dynamic loader lock before we take + * the UST lock internally within handle_pending_statedump(). + */ + handle_pending_statedump(sock_info); + + if (ust_lock()) { + ret = -LTTNG_UST_ERR_EXITING; + goto error; + } + ret = send_reply(sock, &lur); if (ret < 0) { DBG("error sending reply"); @@ -986,13 +1015,6 @@ int handle_message(struct sock_info *sock_info, error: ust_unlock(); - /* - * Performed delayed statedump operations outside of the UST - * lock. We need to take the dynamic loader lock before we take - * the UST lock internally within handle_pending_statedump(). - */ - handle_pending_statedump(sock_info); - return ret; } @@ -1239,7 +1261,18 @@ char *get_map_shm(struct sock_info *sock_info) lttng_ust_unlock_fd_tracker(); goto error; } - lttng_ust_add_fd_to_tracker(wait_shm_fd); + + ret = lttng_ust_add_fd_to_tracker(wait_shm_fd); + if (ret < 0) { + ret = close(wait_shm_fd); + if (!ret) { + PERROR("Error closing fd"); + } + lttng_ust_unlock_fd_tracker(); + goto error; + } + + wait_shm_fd = ret; lttng_ust_unlock_fd_tracker(); wait_shm_mmap = mmap(NULL, page_size, PROT_READ, @@ -1331,7 +1364,7 @@ static void *ust_listener_thread(void *arg) { struct sock_info *sock_info = arg; - int sock, ret, prev_connect_failed = 0, has_waited = 0; + int sock, ret, prev_connect_failed = 0, has_waited = 0, fd; long timeout; lttng_ust_fixup_tls(); @@ -1363,6 +1396,10 @@ restart: prev_connect_failed = 0; } + if (ust_lock()) { + goto quit; + } + if (sock_info->socket != -1) { /* FD tracker is updated by ustcomm_close_unix_sock() */ ret = ustcomm_close_unix_sock(sock_info->socket); @@ -1382,9 +1419,6 @@ restart: sock_info->notify_socket = -1; } - if (ust_lock()) { - goto quit; - } /* * Register. We need to perform both connect and sending @@ -1411,9 +1445,21 @@ restart: ust_unlock(); goto restart; } - lttng_ust_add_fd_to_tracker(ret); - lttng_ust_unlock_fd_tracker(); + fd = ret; + ret = lttng_ust_add_fd_to_tracker(fd); + if (ret < 0) { + ret = close(fd); + if (ret) { + PERROR("close on sock_info->socket"); + } + ret = -1; + lttng_ust_unlock_fd_tracker(); + ust_unlock(); + goto quit; + } + sock_info->socket = ret; + lttng_ust_unlock_fd_tracker(); ust_unlock(); /* @@ -1482,9 +1528,22 @@ restart: ust_unlock(); goto restart; } - lttng_ust_add_fd_to_tracker(ret); - lttng_ust_unlock_fd_tracker(); + + fd = ret; + ret = lttng_ust_add_fd_to_tracker(fd); + if (ret < 0) { + ret = close(fd); + if (ret) { + PERROR("close on sock_info->notify_socket"); + } + ret = -1; + lttng_ust_unlock_fd_tracker(); + ust_unlock(); + goto quit; + } + sock_info->notify_socket = ret; + lttng_ust_unlock_fd_tracker(); ust_unlock(); /* @@ -1646,6 +1705,7 @@ void __attribute__((constructor)) lttng_ust_init(void) * sessiond before the init functions are completed). */ init_usterr(); + lttng_ust_getenv_init(); /* Needs init_usterr() to be completed. */ init_tracepoint(); lttng_ust_init_fd_tracker(); lttng_ust_clock_init(); @@ -1664,6 +1724,8 @@ void __attribute__((constructor)) lttng_ust_init(void) timeout_mode = get_constructor_timeout(&constructor_timeout); + get_allow_blocking(); + ret = sem_init(&constructor_wait, 0, 0); if (ret) { PERROR("sem_init");