Fix: Cleanup local_apps sock_info in lttng_ust_cleanup
[lttng-ust.git] / liblttng-ust / lttng-ust-comm.c
index cc5188f6112cb744ddd45297973cef532201d9a6..7d885a551e2f289f4f11728613d1d1fdc4a38d52 100644 (file)
 #include "lttng-tracer-core.h"
 #include "compat.h"
 #include "../libringbuffer/tlsfixup.h"
-#include "lttng-ust-baddr.h"
+#include "lttng-ust-statedump.h"
 #include "clock.h"
 #include "../libringbuffer/getcpu.h"
+#include "getenv.h"
 
 /*
  * Has lttng ust comm constructor been called ?
@@ -316,11 +317,11 @@ const char *get_lttng_home_dir(void)
 {
        const char *val;
 
-       val = (const char *) getenv("LTTNG_HOME");
+       val = (const char *) lttng_secure_getenv("LTTNG_HOME");
        if (val != NULL) {
                return val;
        }
-       return (const char *) getenv("HOME");
+       return (const char *) lttng_secure_getenv("HOME");
 }
 
 /*
@@ -402,7 +403,7 @@ int setup_local_apps(void)
 
 /*
  * Get notify_sock timeout, in ms.
- * -1: don't wait. 0: wait forever. >0: timeout, in ms.
+ * -1: wait forever. 0: don't wait. >0: timeout, in ms.
  */
 static
 long get_timeout(void)
@@ -425,7 +426,7 @@ long get_notify_sock_timeout(void)
 }
 
 /*
- * Return values: -1: don't wait. 0: wait forever. 1: timeout wait.
+ * Return values: -1: wait forever. 0: don't wait. 1: timeout wait.
  */
 static
 int get_constructor_timeout(struct timespec *constructor_timeout)
@@ -448,7 +449,8 @@ int get_constructor_timeout(struct timespec *constructor_timeout)
         */
        ret = clock_gettime(CLOCK_REALTIME, constructor_timeout);
        if (ret) {
-               return -1;
+               /* Don't wait. */
+               return 0;
        }
        constructor_timeout->tv_sec += constructor_delay_ms / 1000UL;
        constructor_timeout->tv_nsec +=
@@ -457,6 +459,7 @@ int get_constructor_timeout(struct timespec *constructor_timeout)
                constructor_timeout->tv_sec++;
                constructor_timeout->tv_nsec -= 1000000000UL;
        }
+       /* Timeout wait (constructor_delay_ms). */
        return 1;
 }
 
@@ -1117,8 +1120,6 @@ error:
 static
 void wait_for_sessiond(struct sock_info *sock_info)
 {
-       int ret;
-
        if (ust_lock()) {
                goto quit;
        }
@@ -1134,23 +1135,32 @@ void wait_for_sessiond(struct sock_info *sock_info)
 
        DBG("Waiting for %s apps sessiond", sock_info->name);
        /* Wait for futex wakeup */
-       if (uatomic_read((int32_t *) sock_info->wait_shm_mmap) == 0) {
-               ret = futex_async((int32_t *) sock_info->wait_shm_mmap,
-                       FUTEX_WAIT, 0, NULL, NULL, 0);
-               if (ret < 0) {
-                       if (errno == EFAULT) {
-                               wait_poll_fallback = 1;
-                               DBG(
+       if (uatomic_read((int32_t *) sock_info->wait_shm_mmap))
+               goto end_wait;
+
+       while (futex_async((int32_t *) sock_info->wait_shm_mmap,
+                       FUTEX_WAIT, 0, NULL, NULL, 0)) {
+               switch (errno) {
+               case EWOULDBLOCK:
+                       /* Value already changed. */
+                       goto end_wait;
+               case EINTR:
+                       /* Retry if interrupted by signal. */
+                       break;  /* Get out of switch. */
+               case EFAULT:
+                       wait_poll_fallback = 1;
+                       DBG(
 "Linux kernels 2.6.33 to 3.0 (with the exception of stable versions) "
 "do not support FUTEX_WAKE on read-only memory mappings correctly. "
 "Please upgrade your kernel "
 "(fix is commit 9ea71503a8ed9184d2d0b8ccc4d269d05f7940ae in Linux kernel "
 "mainline). LTTng-UST will use polling mode fallback.");
-                               if (ust_debug())
-                                       PERROR("futex");
-                       }
+                       if (ust_debug())
+                               PERROR("futex");
+                       goto end_wait;
                }
        }
+end_wait:
        return;
 
 quit:
@@ -1449,7 +1459,7 @@ void __attribute__((constructor)) lttng_ust_init(void)
        init_tracepoint();
        lttng_ust_clock_init();
        lttng_ust_getcpu_init();
-       lttng_ust_baddr_statedump_init();
+       lttng_ust_statedump_init();
        lttng_ring_buffer_metadata_client_init();
        lttng_ring_buffer_client_overwrite_init();
        lttng_ring_buffer_client_overwrite_rt_init();
@@ -1551,9 +1561,7 @@ static
 void lttng_ust_cleanup(int exiting)
 {
        cleanup_sock_info(&global_apps, exiting);
-       if (local_apps.allowed) {
-               cleanup_sock_info(&local_apps, exiting);
-       }
+       cleanup_sock_info(&local_apps, exiting);
        /*
         * The teardown in this function all affect data structures
         * accessed under the UST lock by the listener thread. This
@@ -1570,7 +1578,7 @@ void lttng_ust_cleanup(int exiting)
        lttng_ring_buffer_client_overwrite_rt_exit();
        lttng_ring_buffer_client_overwrite_exit();
        lttng_ring_buffer_metadata_client_exit();
-       lttng_ust_baddr_statedump_destroy();
+       lttng_ust_statedump_destroy();
        exit_tracepoint();
        if (!exiting) {
                /* Reinitialize values for fork */
This page took 0.024323 seconds and 4 git commands to generate.