We allow the ust_mutex lock to be nested within the same thread using the
ust_mutex_nest counter. When calling ust_lock(), ust_lock_nocheck() or
ust_unlock() twice or more in the same thread would result in an error
message being thrown.

This error message always appear when an application calls fork(3) (with
liblttng-ust-fork preloaded), the thread would lock before the fork(3) in
ust_before_fork() and the child would lock again during 
lttng_after_fork_child().

Signed-off-by: Gabriel-Andrew Pollo-Guilbert 
<gabriel.pollo-guilb...@efficios.com>
---
 liblttng-ust/lttng-ust-comm.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c
index 61dbb41b..a6449bbc 100644
--- a/liblttng-ust/lttng-ust-comm.c
+++ b/liblttng-ust/lttng-ust-comm.c
@@ -135,7 +135,9 @@ int ust_lock(void)
                ERR("pthread_setcancelstate: %s", strerror(ret));
        }
        if (oldstate != PTHREAD_CANCEL_ENABLE) {
-               ERR("pthread_setcancelstate: unexpected oldstate");
+               if (!URCU_TLS(ust_mutex_nest)) {
+                       ERR("pthread_setcancelstate: unexpected oldstate");
+               }
        }
        sigfillset(&sig_all_blocked);
        ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
@@ -171,7 +173,9 @@ void ust_lock_nocheck(void)
                ERR("pthread_setcancelstate: %s", strerror(ret));
        }
        if (oldstate != PTHREAD_CANCEL_ENABLE) {
-               ERR("pthread_setcancelstate: unexpected oldstate");
+               if (!URCU_TLS(ust_mutex_nest)) {
+                       ERR("pthread_setcancelstate: unexpected oldstate");
+               }
        }
        sigfillset(&sig_all_blocked);
        ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
@@ -210,7 +214,9 @@ void ust_unlock(void)
                ERR("pthread_setcancelstate: %s", strerror(ret));
        }
        if (oldstate != PTHREAD_CANCEL_DISABLE) {
-               ERR("pthread_setcancelstate: unexpected oldstate");
+               if (URCU_TLS(ust_mutex_nest)) {
+                       ERR("pthread_setcancelstate: unexpected oldstate");
+               }
        }
 }
 
-- 
2.21.0

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Reply via email to