[lttng-ust] Ignore unexpected old state whennesting ust_mutex in the same thread
diff mbox series

Message ID 20190528161837.29477-1-gabriel.pollo-guilbert@efficios.com
State New
Headers show
Series
  • [lttng-ust] Ignore unexpected old state whennesting ust_mutex in the same thread
Related show

Commit Message

Gabriel-Andrew Pollo-Guilbert May 28, 2019, 4:18 p.m. UTC
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-guilbert at efficios.com>
---
 liblttng-ust/lttng-ust-comm.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Patch
diff mbox series

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");
+		}
 	}
 }