Fix: application exit race with pthread cancel
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 17 Aug 2015 16:50:34 +0000 (09:50 -0700)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 17 Aug 2015 17:05:37 +0000 (10:05 -0700)
Listener threads can be cancelled with ust lock held, which can hang the
following ust cleanup routine, because tracepoint probe unregister needs
to take the ust lock.

Fix this by disabling pthread cancellation for the entire duration of
the ust lock.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/lttng-ust-comm.c

index 7d885a551e2f289f4f11728613d1d1fdc4a38d52..e1426139d064984decf8066c6d096e121b556d7c 100644 (file)
@@ -114,8 +114,15 @@ static int lttng_ust_comm_should_quit;
 int ust_lock(void)
 {
        sigset_t sig_all_blocked, orig_mask;
-       int ret;
+       int ret, oldstate;
 
+       ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
+       if (ret) {
+               ERR("pthread_setcancelstate: %s", strerror(ret));
+       }
+       if (oldstate != PTHREAD_CANCEL_ENABLE) {
+               ERR("pthread_setcancelstate: unexpected oldstate");
+       }
        sigfillset(&sig_all_blocked);
        ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
        if (ret) {
@@ -143,8 +150,15 @@ int ust_lock(void)
 void ust_lock_nocheck(void)
 {
        sigset_t sig_all_blocked, orig_mask;
-       int ret;
+       int ret, oldstate;
 
+       ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
+       if (ret) {
+               ERR("pthread_setcancelstate: %s", strerror(ret));
+       }
+       if (oldstate != PTHREAD_CANCEL_ENABLE) {
+               ERR("pthread_setcancelstate: unexpected oldstate");
+       }
        sigfillset(&sig_all_blocked);
        ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
        if (ret) {
@@ -164,7 +178,7 @@ void ust_lock_nocheck(void)
 void ust_unlock(void)
 {
        sigset_t sig_all_blocked, orig_mask;
-       int ret;
+       int ret, oldstate;
 
        sigfillset(&sig_all_blocked);
        ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
@@ -177,6 +191,13 @@ void ust_unlock(void)
        if (ret) {
                ERR("pthread_sigmask: %s", strerror(ret));
        }
+       ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
+       if (ret) {
+               ERR("pthread_setcancelstate: %s", strerror(ret));
+       }
+       if (oldstate != PTHREAD_CANCEL_DISABLE) {
+               ERR("pthread_setcancelstate: unexpected oldstate");
+       }
 }
 
 /*
This page took 0.026192 seconds and 4 git commands to generate.