[lttng-dev] [PATCH lttng-ust 2/2] Use ust_lock on fd tracker add operation for atomicity against fork

Jonathan Rajotte jonathan.rajotte-julien at efficios.com
Thu Feb 1 22:28:12 UTC 2018


Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---
 liblttng-ust/lttng-ust-comm.c | 8 ++++++++
 liblttng-ust/lttng-ust-elf.c  | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c
index 32ba3c1..f4b7b53 100644
--- a/liblttng-ust/lttng-ust-comm.c
+++ b/liblttng-ust/lttng-ust-comm.c
@@ -1255,10 +1255,16 @@ char *get_map_shm(struct sock_info *sock_info)
 		goto error;
 	}
 
+	if (ust_lock()) {
+		ust_unlock();
+		goto error;
+	}
+
 	lttng_ust_lock_fd_tracker();
 	wait_shm_fd = get_wait_shm(sock_info, page_size);
 	if (wait_shm_fd < 0) {
 		lttng_ust_unlock_fd_tracker();
+		ust_unlock();
 		goto error;
 	}
 
@@ -1269,11 +1275,13 @@ char *get_map_shm(struct sock_info *sock_info)
 			PERROR("Error closing fd");
 		}
 		lttng_ust_unlock_fd_tracker();
+		ust_unlock();
 		goto error;
 	}
 
 	wait_shm_fd = ret;
 	lttng_ust_unlock_fd_tracker();
+	ust_unlock();
 
 	wait_shm_mmap = mmap(NULL, page_size, PROT_READ,
 		  MAP_SHARED, wait_shm_fd, 0);
diff --git a/liblttng-ust/lttng-ust-elf.c b/liblttng-ust/lttng-ust-elf.c
index c073e7a..03c715a 100644
--- a/liblttng-ust/lttng-ust-elf.c
+++ b/liblttng-ust/lttng-ust-elf.c
@@ -256,10 +256,16 @@ struct lttng_ust_elf *lttng_ust_elf_create(const char *path)
 		goto error;
 	}
 
+	if (ust_lock()) {
+		ust_unlock();
+		goto error;
+	}
+
 	lttng_ust_lock_fd_tracker();
 	fd = open(elf->path, O_RDONLY | O_CLOEXEC);
 	if (fd < 0) {
 		lttng_ust_unlock_fd_tracker();
+		ust_unlock();
 		goto error;
 	}
 
@@ -271,10 +277,12 @@ struct lttng_ust_elf *lttng_ust_elf_create(const char *path)
 		}
 		ret = -1;
 		lttng_ust_unlock_fd_tracker();
+		ust_unlock();
 		goto error;
 	}
 	elf->fd = ret;
 	lttng_ust_unlock_fd_tracker();
+	ust_unlock();
 
 	if (lttng_ust_read(elf->fd, e_ident, EI_NIDENT) < EI_NIDENT) {
 		goto error;
-- 
2.7.4



More information about the lttng-dev mailing list