From a0ba721c2d0dd5eccf94bf210a85dcd255385c59 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Wed, 9 Sep 2015 19:40:19 -0400 Subject: [PATCH] Add the filter expression to the enable_event agent protocol message MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The filter expression is part of an event rule, so should be sent along with the event name and log level. This bumps the protocol version to 2.0, and will require UST agents to be updated. Signed-off-by: Alexandre Montplaisir Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/agent.c | 30 ++++++++++++++++++++++++++++-- src/bin/lttng-sessiond/agent.h | 2 +- src/common/sessiond-comm/agent.h | 4 +++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.c index 35f0e578a..def13707b 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.c @@ -360,7 +360,9 @@ error: static int enable_event(struct agent_app *app, struct agent_event *event) { int ret; + char *bytes_to_send; uint64_t data_size; + size_t filter_expression_length; uint32_t reply_ret_code; struct lttcomm_agent_enable msg; struct lttcomm_agent_generic_reply reply; @@ -372,7 +374,16 @@ static int enable_event(struct agent_app *app, struct agent_event *event) DBG2("Agent enabling event %s for app pid: %d and socket %d", event->name, app->pid, app->sock->fd); - data_size = sizeof(msg); + /* + * Calculate the payload's size, which is the fixed-size struct followed + * by the variable-length filter expression (+1 for the ending \0). + */ + if (!event->filter_expression) { + filter_expression_length = 0; + } else { + filter_expression_length = strlen(event->filter_expression) + 1; + } + data_size = sizeof(msg) + filter_expression_length; ret = send_header(app->sock, data_size, AGENT_CMD_ENABLE, 0); if (ret < 0) { @@ -383,7 +394,22 @@ static int enable_event(struct agent_app *app, struct agent_event *event) msg.loglevel_value = event->loglevel_value; msg.loglevel_type = event->loglevel_type; strncpy(msg.name, event->name, sizeof(msg.name)); - ret = send_payload(app->sock, &msg, sizeof(msg)); + msg.filter_expression_length = filter_expression_length; + + bytes_to_send = zmalloc(data_size); + if (!bytes_to_send) { + ret = LTTNG_ERR_NOMEM; + goto error; + } + + memcpy(bytes_to_send, &msg, sizeof(msg)); + if (filter_expression_length > 0) { + memcpy(bytes_to_send + sizeof(msg), event->filter_expression, + filter_expression_length); + } + + ret = send_payload(app->sock, bytes_to_send, data_size); + free(bytes_to_send); if (ret < 0) { goto error_io; } diff --git a/src/bin/lttng-sessiond/agent.h b/src/bin/lttng-sessiond/agent.h index 7fba3e9e3..af8254e1b 100644 --- a/src/bin/lttng-sessiond/agent.h +++ b/src/bin/lttng-sessiond/agent.h @@ -24,7 +24,7 @@ #include /* Agent protocol version that is verified during the agent registration. */ -#define AGENT_MAJOR_VERSION 1 +#define AGENT_MAJOR_VERSION 2 #define AGENT_MINOR_VERSION 0 /* diff --git a/src/common/sessiond-comm/agent.h b/src/common/sessiond-comm/agent.h index f3564550b..e8d182515 100644 --- a/src/common/sessiond-comm/agent.h +++ b/src/common/sessiond-comm/agent.h @@ -55,12 +55,14 @@ struct lttcomm_agent_hdr { } LTTNG_PACKED; /* - * Enable event command payload. + * Enable event command payload. Will be immediately followed by the + * variable-length string representing the filter expression. */ struct lttcomm_agent_enable { uint32_t loglevel_value; uint32_t loglevel_type; char name[LTTNG_SYMBOL_NAME_LEN]; + uint32_t filter_expression_length; } LTTNG_PACKED; /* -- 2.34.1