Fix: race between lttng-ust getenv() and application setenv()
[lttng-ust.git] / liblttng-ust / lttng-ust-comm.c
index 7cd6a227d66c3bede0f7e244a02038c2c8de668b..43728ff47613d2d2fb0b8e092268ea1c60243f79 100644 (file)
@@ -35,6 +35,7 @@
 #include <time.h>
 #include <assert.h>
 #include <signal.h>
+#include <limits.h>
 #include <urcu/uatomic.h>
 #include <urcu/futex.h>
 #include <urcu/compiler.h>
@@ -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,30 @@ int get_constructor_timeout(struct timespec *constructor_timeout)
        return 1;
 }
 
+static
+void get_blocking_retry_timeout(void)
+{
+       const char *str_blocking_retry_timeout =
+               lttng_getenv("LTTNG_UST_BLOCKING_RETRY_TIMEOUT");
+
+       if (str_blocking_retry_timeout) {
+               long timeout = strtol(str_blocking_retry_timeout, NULL, 10);
+
+               if (timeout < 0)
+                       timeout = -1;
+               if (timeout > INT_MAX) {
+                       WARN("Saturating %s value from %ld to %d\n",
+                               "LTTNG_UST_BLOCKING_RETRY_TIMEOUT",
+                               timeout, INT_MAX);
+                       timeout = INT_MAX;
+               }
+               DBG("%s environment variable value is %ld",
+                       "LTTNG_UST_BLOCKING_RETRY_TIMEOUT",
+                       timeout);
+               lttng_ust_ringbuffer_set_retry_timeout(timeout);
+       }
+}
+
 static
 int register_to_sessiond(int socket, enum ustctl_socket_type type)
 {
@@ -1654,6 +1679,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();
@@ -1672,6 +1698,8 @@ void __attribute__((constructor)) lttng_ust_init(void)
 
        timeout_mode = get_constructor_timeout(&constructor_timeout);
 
+       get_blocking_retry_timeout();
+
        ret = sem_init(&constructor_wait, 0, 0);
        if (ret) {
                PERROR("sem_init");
This page took 0.026154 seconds and 4 git commands to generate.