fix: Handle sys_futex with async cancel, add missing pthread_join
[lttng-ust.git] / liblttng-ust / lttng-ust-comm.c
index 798c10a36c47bc1e7257227ba57dc46945fac853..f41863628c9a097d8394eaa35a2ce2e834ee4e12 100644 (file)
@@ -22,7 +22,6 @@
 #define _LGPL_SOURCE
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <sys/prctl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -46,6 +45,7 @@
 #include <usterr-signal-safe.h>
 #include "tracepoint-internal.h"
 #include "ltt-tracer-core.h"
+#include "compat.h"
 
 /*
  * Has lttng ust comm constructor been called ?
@@ -159,7 +159,6 @@ static
 int register_app_to_sessiond(int socket)
 {
        ssize_t ret;
-       int prctl_ret;
        struct {
                uint32_t major;
                uint32_t minor;
@@ -178,11 +177,7 @@ int register_app_to_sessiond(int socket)
        reg_msg.uid = getuid();
        reg_msg.gid = getgid();
        reg_msg.bits_per_long = CAA_BITS_PER_LONG;
-       prctl_ret = prctl(PR_GET_NAME, (unsigned long) reg_msg.name, 0, 0, 0);
-       if (prctl_ret) {
-               ERR("Error executing prctl");
-               return -errno;
-       }
+       lttng_ust_getprocname(reg_msg.name);
 
        ret = ustcomm_send_unix_sock(socket, &reg_msg, sizeof(reg_msg));
        if (ret >= 0 && ret != sizeof(reg_msg))
@@ -583,7 +578,7 @@ error:
 static
 void wait_for_sessiond(struct sock_info *sock_info)
 {
-       int ret;
+       int ret, oldtype;
 
        ust_lock();
        if (lttng_ust_comm_should_quit) {
@@ -600,6 +595,14 @@ void wait_for_sessiond(struct sock_info *sock_info)
        ust_unlock();
 
        DBG("Waiting for %s apps sessiond", sock_info->name);
+       /*
+        * sys_futex does not honor pthread cancel requests. Set to
+        * async.
+        */
+       ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+       if (ret) {
+               ERR("Error setting thread cancel type");
+       }
        /* 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,
@@ -618,6 +621,10 @@ void wait_for_sessiond(struct sock_info *sock_info)
                        }
                }
        }
+       ret = pthread_setcanceltype(oldtype, &oldtype);
+       if (ret) {
+               ERR("Error setting thread cancel type");
+       }
        return;
 
 quit:
@@ -918,6 +925,7 @@ void __attribute__((destructor)) lttng_ust_exit(void)
        lttng_ust_comm_should_quit = 1;
        ust_unlock();
 
+       /* cancel threads */
        ret = pthread_cancel(global_apps.ust_listener);
        if (ret) {
                ERR("Error cancelling global ust listener thread");
@@ -928,6 +936,17 @@ void __attribute__((destructor)) lttng_ust_exit(void)
                        ERR("Error cancelling local ust listener thread");
                }
        }
+       /* join threads */
+       ret = pthread_join(global_apps.ust_listener, NULL);
+       if (ret) {
+               ERR("Error joining global ust listener thread");
+       }
+       if (local_apps.allowed) {
+               ret = pthread_join(local_apps.ust_listener, NULL);
+               if (ret) {
+                       ERR("Error joining local ust listener thread");
+               }
+       }
        lttng_ust_cleanup(1);
 }
 
This page took 0.025402 seconds and 4 git commands to generate.