Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: ylamarre@efficios.com (Yannick Lamarre)
Subject: [lttng-dev] [RFC PATCH lttng-tools 12/18] Integrate serialized communication in lttng-ctl and sessiond
Date: Thu, 18 Apr 2019 12:18:44 -0400	[thread overview]
Message-ID: <20190418161850.1536-13-ylamarre@efficios.com> (raw)
In-Reply-To: <20190418161850.1536-1-ylamarre@efficios.com>

lttng-ctl and lttng-sessiond use serialized communication for
messages using lttng_event_context.

Signed-off-by: Yannick Lamarre <ylamarre at efficios.com>
---
 include/lttng/event-internal.h           |  4 ++++
 src/bin/lttng-sessiond/client.c          | 16 +++++++++-------
 src/common/sessiond-comm/sessiond-comm.h |  2 +-
 src/lib/lttng-ctl/lttng-ctl.c            | 12 +-----------
 4 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/include/lttng/event-internal.h b/include/lttng/event-internal.h
index 25a88448..09b4d232 100644
--- a/include/lttng/event-internal.h
+++ b/include/lttng/event-internal.h
@@ -57,4 +57,8 @@ struct lttng_event_extended {
 LTTNG_HIDDEN
 struct lttng_event *lttng_event_copy(const struct lttng_event *event);
 
+int lttng_event_context_serialize(struct lttng_event_context_serialized *dst, const struct lttng_event_context *src);
+int lttng_event_context_deserialize(struct lttng_event_context *dst, const struct lttng_event_context_serialized *src);
+int lttng_event_perf_counter_ctx_serialize(struct lttng_event_perf_counter_ctx_serialized *dst, const struct lttng_event_perf_counter_ctx *src);
+int lttng_event_perf_counter_ctx_deserialize(struct lttng_event_perf_counter_ctx *dst, const struct lttng_event_perf_counter_ctx_serialized *src);
 #endif /* LTTNG_EVENT_INTERNAL_H */
diff --git a/src/bin/lttng-sessiond/client.c b/src/bin/lttng-sessiond/client.c
index 0e36e5ad..24e688c5 100644
--- a/src/bin/lttng-sessiond/client.c
+++ b/src/bin/lttng-sessiond/client.c
@@ -1069,6 +1069,8 @@ skip_domain:
 	switch (cmd_ctx->lsm->cmd_type) {
 	case LTTNG_ADD_CONTEXT:
 	{
+		struct lttng_event_context evt_ctx;
+		lttng_event_context_deserialize(&evt_ctx, &cmd_ctx->lsm->u.context.ctx);
 		/*
 		 * An LTTNG_ADD_CONTEXT command might have a supplementary
 		 * payload if the context being added is an application context.
@@ -1095,7 +1097,7 @@ skip_domain:
 				ret = -LTTNG_ERR_NOMEM;
 				goto error;
 			}
-			cmd_ctx->lsm->u.context.ctx.u.app_ctx.provider_name =
+			evt_ctx.u.app_ctx.provider_name =
 					provider_name;
 
 			context_name = zmalloc(context_name_len + 1);
@@ -1103,7 +1105,7 @@ skip_domain:
 				ret = -LTTNG_ERR_NOMEM;
 				goto error_add_context;
 			}
-			cmd_ctx->lsm->u.context.ctx.u.app_ctx.ctx_name =
+			evt_ctx.u.app_ctx.ctx_name =
 					context_name;
 
 			ret = lttcomm_recv_unix_sock(sock, provider_name,
@@ -1126,14 +1128,14 @@ skip_domain:
 		ret = cmd_add_context(cmd_ctx->session,
 				cmd_ctx->lsm->domain.type,
 				cmd_ctx->lsm->u.context.channel_name,
-				&cmd_ctx->lsm->u.context.ctx,
+				&evt_ctx,
 				kernel_poll_pipe[1]);
 
-		cmd_ctx->lsm->u.context.ctx.u.app_ctx.provider_name = NULL;
-		cmd_ctx->lsm->u.context.ctx.u.app_ctx.ctx_name = NULL;
+		evt_ctx.u.app_ctx.provider_name = NULL;
+		evt_ctx.u.app_ctx.ctx_name = NULL;
 error_add_context:
-		free(cmd_ctx->lsm->u.context.ctx.u.app_ctx.provider_name);
-		free(cmd_ctx->lsm->u.context.ctx.u.app_ctx.ctx_name);
+		free(evt_ctx.u.app_ctx.provider_name);
+		free(evt_ctx.u.app_ctx.ctx_name);
 		if (ret < 0) {
 			goto error;
 		}
diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h
index 2760af3a..78b18185 100644
--- a/src/common/sessiond-comm/sessiond-comm.h
+++ b/src/common/sessiond-comm/sessiond-comm.h
@@ -410,7 +410,7 @@ struct lttcomm_session_msg {
 		/* Context */
 		struct {
 			char channel_name[LTTNG_SYMBOL_NAME_LEN];
-			struct lttng_event_context ctx LTTNG_PACKED;
+			struct lttng_event_context_serialized ctx;
 			uint32_t provider_name_len;
 			uint32_t context_name_len;
 		} LTTNG_PACKED context;
diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c
index 789534c8..686a98ef 100644
--- a/src/lib/lttng-ctl/lttng-ctl.c
+++ b/src/lib/lttng-ctl/lttng-ctl.c
@@ -821,17 +821,7 @@ int lttng_add_context(struct lttng_handle *handle,
 		memcpy(buf, provider_name, provider_len);
 		memcpy(buf + provider_len, ctx_name, ctx_len);
 	}
-	memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
-
-	if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
-		/*
-		 * Don't leak application addresses to the sessiond.
-		 * This is only necessary when ctx is for an app ctx otherwise
-		 * the values inside the union (type & config) are overwritten.
-		 */
-		lsm.u.context.ctx.u.app_ctx.provider_name = NULL;
-		lsm.u.context.ctx.u.app_ctx.ctx_name = NULL;
-	}
+	lttng_event_context_serialize(&lsm.u.context.ctx, ctx);
 
 	ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buf, len, NULL);
 end:
-- 
2.11.0



  parent reply	other threads:[~2019-04-18 16:18 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18 16:18 [lttng-dev] [RFC PATCH lttng-tools 00/18] Improvements in sessiond-comm Yannick Lamarre
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 01/18] Fix: Use platform-independant types in sessiond to consumerd communication Yannick Lamarre
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 02/18] Clean-up: Switch enum fields in lttcomm_consumer_msg Yannick Lamarre
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 03/18] Clean-up: Switch enum fields in lttcomm_consumer_status_msg Yannick Lamarre
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 04/18] Clean-up: Switch enum fields in lttcomm_consumer_status_channel Yannick Lamarre
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 05/18] Clean-up: Remove unused structure Yannick Lamarre
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 06/18] Clean-up: Removed deprecated field Yannick Lamarre
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 07/18] Add serialized versions of lttng_channel structs Yannick Lamarre
2019-04-18 19:38   ` Mathieu Desnoyers
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 08/18] Add serdes functions for lttng_channel Yannick Lamarre
2019-04-18 19:32   ` Mathieu Desnoyers
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 09/18] Integrate serialized communication in lttng-ctl and sessiond Yannick Lamarre
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 10/18] Add serialized versions of lttng_event_context structs Yannick Lamarre
2019-04-18 19:41   ` Mathieu Desnoyers
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 11/18] Add serdes functions for lttng_event_context Yannick Lamarre
2019-04-18 19:42   ` Mathieu Desnoyers
2019-04-18 16:18 ` Yannick Lamarre [this message]
2019-04-18 19:44   ` [lttng-dev] [RFC PATCH lttng-tools 12/18] Integrate serialized communication in lttng-ctl and sessiond Mathieu Desnoyers
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 13/18] Add serialized versions of lttng_event structs Yannick Lamarre
2019-04-18 19:45   ` Mathieu Desnoyers
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 14/18] Add serdes functions for lttng_event_context Yannick Lamarre
2019-04-18 19:46   ` Mathieu Desnoyers
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 15/18] Integrate serialized communication in lttng-ctl and sessiond Yannick Lamarre
2019-04-18 19:49   ` Mathieu Desnoyers
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 16/18] Add serialized versions of lttng_event structs Yannick Lamarre
2019-04-18 19:50   ` Mathieu Desnoyers
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 17/18] Add serdes functions for lttng_snapshot_output Yannick Lamarre
2019-04-18 19:52   ` Mathieu Desnoyers
2019-04-18 16:18 ` [lttng-dev] [RFC PATCH lttng-tools 18/18] Integrate serialized communication in lttng-ctl and sessiond Yannick Lamarre
2019-04-18 19:58   ` Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190418161850.1536-13-ylamarre@efficios.com \
    --to=ylamarre@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox