Add the filter expression to the enable_event agent protocol message
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Wed, 9 Sep 2015 23:40:19 +0000 (19:40 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 22 Oct 2015 20:36:24 +0000 (16:36 -0400)
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 <alexmonthy@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/agent.c
src/bin/lttng-sessiond/agent.h
src/common/sessiond-comm/agent.h

index 35f0e578a0da725863f1b07be9d385a577371ea2..def13707bdf52fd40149dc0d9705393b4652b618 100644 (file)
@@ -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;
        }
index 7fba3e9e31c7400865aa1ae4727e49fcc72c6fb0..af8254e1b0433d2b1f016f7b2c09c86ef44dba8c 100644 (file)
@@ -24,7 +24,7 @@
 #include <lttng/lttng.h>
 
 /* 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
 
 /*
index f3564550b746b47d4c00954545f86a4df7f70e20..e8d182515888cd0273ec8622eb8f47861ec8fc90 100644 (file)
@@ -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;
 
 /*
This page took 0.036079 seconds and 4 git commands to generate.