Version 2.0.8
[lttng-ust.git] / liblttng-ust / lttng-ust-comm.c
index 8c864f8ce595621434cfac4a08dec1aa705d5671..dece0ee6e70d42ef4982e545884a6f944e550fc8 100644 (file)
@@ -136,6 +136,15 @@ extern void ltt_ring_buffer_client_overwrite_exit(void);
 extern void ltt_ring_buffer_client_discard_exit(void);
 extern void ltt_ring_buffer_metadata_client_exit(void);
 
+/*
+ * Force a read (imply TLS fixup for dlopen) of TLS variables.
+ */
+static
+void lttng_fixup_nest_count_tls(void)
+{
+       asm volatile ("" : : "m" (lttng_ust_nest_count));
+}
+
 static
 int setup_local_apps(void)
 {
@@ -147,14 +156,16 @@ int setup_local_apps(void)
         * Disallow per-user tracing for setuid binaries.
         */
        if (uid != geteuid()) {
-               local_apps.allowed = 0;
+               assert(local_apps.allowed == 0);
                return 0;
-       } else {
-               local_apps.allowed = 1;
        }
        home_dir = (const char *) getenv("HOME");
-       if (!home_dir)
+       if (!home_dir) {
+               WARN("HOME environment variable not set. Disabling LTTng-UST per-user tracing.");
+               assert(local_apps.allowed == 0);
                return -ENOENT;
+       }
+       local_apps.allowed = 1;
        snprintf(local_apps.sock_path, PATH_MAX,
                 DEFAULT_HOME_APPS_UNIX_SOCK, home_dir);
        snprintf(local_apps.wait_shm_path, PATH_MAX,
@@ -526,9 +537,9 @@ int get_wait_shm(struct sock_info *sock_info, size_t mmap_size)
                        ret = ftruncate(wait_shm_fd, mmap_size);
                        if (ret) {
                                PERROR("ftruncate");
-                               exit(EXIT_FAILURE);
+                               _exit(EXIT_FAILURE);
                        }
-                       exit(EXIT_SUCCESS);
+                       _exit(EXIT_SUCCESS);
                }
                /*
                 * For local shm, we need to have rw access to accept
@@ -540,13 +551,13 @@ int get_wait_shm(struct sock_info *sock_info, size_t mmap_size)
                 */
                if (!sock_info->global && errno != EACCES) {
                        ERR("Error opening shm %s", sock_info->wait_shm_path);
-                       exit(EXIT_FAILURE);
+                       _exit(EXIT_FAILURE);
                }
                /*
                 * The shm exists, but we cannot open it RW. Report
                 * success.
                 */
-               exit(EXIT_SUCCESS);
+               _exit(EXIT_SUCCESS);
        } else {
                return -1;
        }
@@ -846,6 +857,7 @@ void __attribute__((constructor)) lttng_ust_init(void)
 {
        struct timespec constructor_timeout;
        sigset_t sig_all_blocked, orig_parent_mask;
+       pthread_attr_t thread_attr;
        int timeout_mode;
        int ret;
 
@@ -860,6 +872,7 @@ void __attribute__((constructor)) lttng_ust_init(void)
        lttng_fixup_event_tls();
        lttng_fixup_ringbuffer_tls();
        lttng_fixup_vtid_tls();
+       lttng_fixup_nest_count_tls();
 
        /*
         * We want precise control over the order in which we construct
@@ -880,7 +893,7 @@ void __attribute__((constructor)) lttng_ust_init(void)
 
        ret = setup_local_apps();
        if (ret) {
-               ERR("Error setting up to local apps");
+               DBG("local apps setup returned %d", ret);
        }
 
        /* A new thread created by pthread_create inherits the signal mask
@@ -894,13 +907,22 @@ void __attribute__((constructor)) lttng_ust_init(void)
                ERR("pthread_sigmask: %s", strerror(ret));
        }
 
-       ret = pthread_create(&global_apps.ust_listener, NULL,
+       ret = pthread_attr_init(&thread_attr);
+       if (ret) {
+               ERR("pthread_attr_init: %s", strerror(ret));
+       }
+       ret = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
+       if (ret) {
+               ERR("pthread_attr_setdetachstate: %s", strerror(ret));
+       }
+
+       ret = pthread_create(&global_apps.ust_listener, &thread_attr,
                        ust_listener_thread, &global_apps);
        if (ret) {
                ERR("pthread_create global: %s", strerror(ret));
        }
        if (local_apps.allowed) {
-               ret = pthread_create(&local_apps.ust_listener, NULL,
+               ret = pthread_create(&local_apps.ust_listener, &thread_attr,
                                ust_listener_thread, &local_apps);
                if (ret) {
                        ERR("pthread_create local: %s", strerror(ret));
@@ -908,6 +930,10 @@ void __attribute__((constructor)) lttng_ust_init(void)
        } else {
                handle_register_done(&local_apps);
        }
+       ret = pthread_attr_destroy(&thread_attr);
+       if (ret) {
+               ERR("pthread_attr_destroy: %s", strerror(ret));
+       }
 
        /* Restore original signal mask in parent */
        ret = pthread_sigmask(SIG_SETMASK, &orig_parent_mask, NULL);
This page took 0.025543 seconds and 4 git commands to generate.