[lttng-dev] [PATCH lttng-ust] Bugfix for http://bugs.lttng.org/issues/745

Paul Woegerer paul.woegerer at gmail.com
Tue Jun 24 09:38:36 EDT 2014


In case of a fork prevent ust_lock_nocheck() in ust_before_fork() to be
executed before handle_pending_statedump() gets completed.

Signed-off-by: Paul Woegerer <paul_woegerer at mentor.com>
---
 liblttng-ust/lttng-ust-comm.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c
index 5df33f5..7cda59f 100644
--- a/liblttng-ust/lttng-ust-comm.c
+++ b/liblttng-ust/lttng-ust-comm.c
@@ -173,6 +173,7 @@ void ust_unlock(void)
  *   daemon problems).
  */
 static sem_t constructor_wait;
+static sem_t fork_child_wait;
 /*
  * Doing this for both the global and local sessiond.
  */
@@ -502,12 +503,16 @@ int handle_register_done(struct sock_info *sock_info)
 static
 void handle_pending_statedump(struct sock_info *sock_info)
 {
+	int ret;
 	int ctor_passed = sock_info->constructor_sem_posted;
 
 	if (ctor_passed && sock_info->statedump_pending) {
 		sock_info->statedump_pending = 0;
 		lttng_handle_pending_statedump(sock_info);
 	}
+
+	ret = sem_post(&fork_child_wait);
+	assert(!ret);
 }
 
 static
@@ -1436,6 +1441,9 @@ void __attribute__((constructor)) lttng_ust_init(void)
 	ret = sem_init(&constructor_wait, 0, 0);
 	assert(!ret);
 
+	ret = sem_init(&fork_child_wait, 0, 0);
+	assert(!ret);
+
 	ret = setup_local_apps();
 	if (ret) {
 		DBG("local apps setup returned %d", ret);
@@ -1627,6 +1635,12 @@ void ust_before_fork(sigset_t *save_sigset)
 	if (ret == -1) {
 		PERROR("sigprocmask");
 	}
+
+	do {
+		ret = sem_wait(&fork_child_wait);
+	} while (ret < 0 && errno == EINTR);
+	assert(!ret);
+
 	ust_lock_nocheck();
 	rcu_bp_before_fork();
 }
-- 
2.0.0




More information about the lttng-dev mailing list