[ltt-dev] [LTTNG-TOOLS PATCH 2/3] Export a copy of the FD list

Julien Desfossez julien.desfossez at polymtl.ca
Sun Aug 14 23:13:35 EDT 2011


Add a function to liblttkconsumerd to get the current list of FDs open.
Also export lttng_kconsumerd_change_fd_state to allow a modification to
the FD list from an external consumer.

Signed-off-by: Julien Desfossez <julien.desfossez at polymtl.ca>
---
 include/lttng/lttng-kconsumerd.h     |   14 ++++++++++++++
 liblttngkconsumerd/lttngkconsumerd.c |   24 ++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/include/lttng/lttng-kconsumerd.h b/include/lttng/lttng-kconsumerd.h
index 454af6e..a32a953 100644
--- a/include/lttng/lttng-kconsumerd.h
+++ b/include/lttng/lttng-kconsumerd.h
@@ -210,4 +210,18 @@ extern void lttng_kconsumerd_set_error_sock(
 extern void lttng_kconsumerd_set_command_sock_path(
 		struct lttng_kconsumerd_local_data *ctx, char *sock);
 
+/*
+ * Export a copy of the list of FDs
+ * The copy has to be initialised by the caller, the function appends a struct
+ * lttng_kconsumerd_fd per fd to the list
+ */
+extern void lttng_kconsumerd_get_fd_list_copy(
+		struct lttng_kconsumerd_fd_list *copy);
+
+/*
+ * Update a fd according to what we just received.
+ */
+extern void lttng_kconsumerd_change_fd_state(int sessiond_fd,
+		enum lttng_kconsumerd_fd_state state);
+
 #endif /* _LTTNG_KCONSUMERD_H */
diff --git a/liblttngkconsumerd/lttngkconsumerd.c b/liblttngkconsumerd/lttngkconsumerd.c
index 81749be..45c51d9 100644
--- a/liblttngkconsumerd/lttngkconsumerd.c
+++ b/liblttngkconsumerd/lttngkconsumerd.c
@@ -195,9 +195,29 @@ end:
 }
 
 /*
+ * Export a copy of the list of FDs
+ * The copy has to be initialised by the caller, the function appends a struct
+ * lttng_kconsumerd_fd per fd to the list
+ */
+void lttng_kconsumerd_get_fd_list_copy(struct lttng_kconsumerd_fd_list *copy)
+{
+	struct lttng_kconsumerd_fd *tmp_fd;
+	struct lttng_kconsumerd_fd *iter;
+
+	pthread_mutex_lock(&kconsumerd_data.lock);
+	cds_list_for_each_entry(iter, &kconsumerd_data.fd_list.head, list) {
+		tmp_fd = malloc(sizeof(struct lttng_kconsumerd_fd));
+		memcpy(tmp_fd, iter, sizeof(struct lttng_kconsumerd_fd));
+		cds_list_add(&tmp_fd->list, &copy->head);
+	}
+	pthread_mutex_unlock(&kconsumerd_data.lock);
+}
+
+
+/*
  * Update a fd according to what we just received.
  */
-static void kconsumerd_change_fd_state(int sessiond_fd,
+void lttng_kconsumerd_change_fd_state(int sessiond_fd,
 		enum lttng_kconsumerd_fd_state state)
 {
 	struct lttng_kconsumerd_fd *iter;
@@ -321,7 +341,7 @@ static int kconsumerd_consumerd_recv_fd(
 					}
 					break;
 				case UPDATE_STREAM:
-					kconsumerd_change_fd_state(lkm.fd, lkm.state);
+					lttng_kconsumerd_change_fd_state(lkm.fd, lkm.state);
 					break;
 				default:
 					break;
-- 
1.7.4.1





More information about the lttng-dev mailing list