Remove ENABLE_EVENT_* values and fix enable filtering
authorDavid Goulet <dgoulet@efficios.com>
Thu, 14 Nov 2013 19:50:26 +0000 (14:50 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 14 Nov 2013 20:05:59 +0000 (15:05 -0500)
Since every enable event values are now mapped to the same code path,
only use one for the three of them.

This commit also fixes the check for the maximum bytecode length.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/main.c
src/common/sessiond-comm/sessiond-comm.h
src/lib/lttng-ctl/lttng-ctl.c

index bbbc75588c6f044a159f05a9588579f639037ec4..8aea0e77c840e38f3a05b117064fbc21f1f900e9 100644 (file)
@@ -2936,74 +2936,75 @@ skip_domain:
                break;
        }
        case LTTNG_ENABLE_EVENT:
-       case LTTNG_ENABLE_EVENT_WITH_EXCLUSION:
-       case LTTNG_ENABLE_EVENT_WITH_FILTER:
        {
                struct lttng_event_exclusion *exclusion = NULL;
                struct lttng_filter_bytecode *bytecode = NULL;
 
-               if (cmd_ctx->lsm->cmd_type == LTTNG_ENABLE_EVENT ||
-                               (cmd_ctx->lsm->u.enable.exclusion_count == 0 && cmd_ctx->lsm->u.enable.bytecode_len == 0)) {
-                       ret = cmd_enable_event(cmd_ctx->session, &cmd_ctx->lsm->domain,
-                                       cmd_ctx->lsm->u.enable.channel_name,
-                                       &cmd_ctx->lsm->u.enable.event, NULL, NULL, kernel_poll_pipe[1]);
-               } else {
-                       if (cmd_ctx->lsm->u.enable.exclusion_count != 0) {
-                               exclusion = zmalloc(sizeof(struct lttng_event_exclusion) +
-                                               cmd_ctx->lsm->u.enable.exclusion_count * LTTNG_SYMBOL_NAME_LEN);
-                               if (!exclusion) {
-                                       ret = LTTNG_ERR_EXCLUSION_NOMEM;
-                                       goto error;
-                               }
-                               DBG("Receiving var len data from client ...");
-                               exclusion->count = cmd_ctx->lsm->u.enable.exclusion_count;
-                               ret = lttcomm_recv_unix_sock(sock, exclusion->names,
-                                               cmd_ctx->lsm->u.enable.exclusion_count * LTTNG_SYMBOL_NAME_LEN);
-                               if (ret <= 0) {
-                                       DBG("Nothing recv() from client var len data... continuing");
-                                       *sock_error = 1;
-                                       ret = LTTNG_ERR_EXCLUSION_INVAL;
-                                       goto error;
-                               }
+               /* Handle exclusion events and receive it from the client. */
+               if (cmd_ctx->lsm->u.enable.exclusion_count > 0) {
+                       size_t count = cmd_ctx->lsm->u.enable.exclusion_count;
+
+                       exclusion = zmalloc(sizeof(struct lttng_event_exclusion) +
+                                       (count * LTTNG_SYMBOL_NAME_LEN));
+                       if (!exclusion) {
+                               ret = LTTNG_ERR_EXCLUSION_NOMEM;
+                               goto error;
                        }
-                       if (cmd_ctx->lsm->u.enable.bytecode_len != 0) {
-                               bytecode = zmalloc(cmd_ctx->lsm->u.enable.bytecode_len);
-                               if (!bytecode) {
-                                       if (!exclusion)
-                                               free(exclusion);
-                                       ret = LTTNG_ERR_FILTER_NOMEM;
-                                       goto error;
-                               }
-                               /* Receive var. len. data */
-                               DBG("Receiving var len data from client ...");
-                               ret = lttcomm_recv_unix_sock(sock, bytecode,
-                                               cmd_ctx->lsm->u.enable.bytecode_len);
-                               if (ret <= 0) {
-                                       DBG("Nothing recv() from client car len data... continuing");
-                                       *sock_error = 1;
-                                       if (!exclusion)
-                                               free(exclusion);
-                                       ret = LTTNG_ERR_FILTER_INVAL;
-                                       goto error;
-                               }
 
-                               if (bytecode->len + sizeof(*bytecode)
-                                               != cmd_ctx->lsm->u.enable.bytecode_len) {
-                                       free(bytecode);
-                                       if (!exclusion)
-                                               free(exclusion);
-                                       ret = LTTNG_ERR_FILTER_INVAL;
-                                       goto error;
-                               }
+                       DBG("Receiving var len exclusion event list from client ...");
+                       exclusion->count = count;
+                       ret = lttcomm_recv_unix_sock(sock, exclusion->names,
+                                       count * LTTNG_SYMBOL_NAME_LEN);
+                       if (ret <= 0) {
+                               DBG("Nothing recv() from client var len data... continuing");
+                               *sock_error = 1;
+                               free(exclusion);
+                               ret = LTTNG_ERR_EXCLUSION_INVAL;
+                               goto error;
+                       }
+               }
+
+               /* Handle filter and get bytecode from client. */
+               if (cmd_ctx->lsm->u.enable.bytecode_len > 0) {
+                       size_t bytecode_len = cmd_ctx->lsm->u.enable.bytecode_len;
+
+                       if (bytecode_len > LTTNG_FILTER_MAX_LEN) {
+                               ret = LTTNG_ERR_FILTER_INVAL;
+                               free(exclusion);
+                               goto error;
                        }
 
-                       ret = cmd_enable_event(cmd_ctx->session,
-                                       &cmd_ctx->lsm->domain,
-                                       cmd_ctx->lsm->u.enable.channel_name,
-                                       &cmd_ctx->lsm->u.enable.event, bytecode,
-                                       exclusion,
-                                       kernel_poll_pipe[1]);
+                       bytecode = zmalloc(bytecode_len);
+                       if (!bytecode) {
+                               free(exclusion);
+                               ret = LTTNG_ERR_FILTER_NOMEM;
+                               goto error;
+                       }
+
+                       /* Receive var. len. data */
+                       DBG("Receiving var len filter's bytecode from client ...");
+                       ret = lttcomm_recv_unix_sock(sock, bytecode, bytecode_len);
+                       if (ret <= 0) {
+                               DBG("Nothing recv() from client car len data... continuing");
+                               *sock_error = 1;
+                               free(bytecode);
+                               free(exclusion);
+                               ret = LTTNG_ERR_FILTER_INVAL;
+                               goto error;
+                       }
+
+                       if ((bytecode->len + sizeof(*bytecode)) != bytecode_len) {
+                               free(bytecode);
+                               free(exclusion);
+                               ret = LTTNG_ERR_FILTER_INVAL;
+                               goto error;
+                       }
                }
+
+               ret = cmd_enable_event(cmd_ctx->session, &cmd_ctx->lsm->domain,
+                               cmd_ctx->lsm->u.enable.channel_name,
+                               &cmd_ctx->lsm->u.enable.event, bytecode, exclusion,
+                               kernel_poll_pipe[1]);
                break;
        }
        case LTTNG_ENABLE_ALL_EVENT:
index 9a33479f3da604ad00dc5e277a1c26e36a0a321b..2246477f385f5e47496187d2ab73d4804bcaec53 100644 (file)
@@ -80,8 +80,8 @@ enum lttcomm_sessiond_command {
        LTTNG_DISABLE_CONSUMER              = 19,
        LTTNG_ENABLE_CONSUMER               = 20,
        LTTNG_SET_CONSUMER_URI              = 21,
-       LTTNG_ENABLE_EVENT_WITH_FILTER      = 22,
-       LTTNG_ENABLE_EVENT_WITH_EXCLUSION   = 23,
+       /* 22 */
+       /* 23 */
        LTTNG_DATA_PENDING                  = 24,
        LTTNG_SNAPSHOT_ADD_OUTPUT           = 25,
        LTTNG_SNAPSHOT_DEL_OUTPUT           = 26,
index 9a2160533ee909a5b5efb3c924d96b56484a99b0..222d719f8e09b40d37b9a5e9ee7c36d9bb1e1d97 100644 (file)
@@ -734,21 +734,7 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
        }
 
        lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
-
-       /* figure out correct command type, based on if we have a filter or exclusions */
-       if (exclusion_count == 0) {
-               if (filter_expression == NULL) {
-                       if (ev->name[0] != '\0') {
-                               lsm.cmd_type = LTTNG_ENABLE_EVENT;
-                       } else {
-                               lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT;
-                       }
-               } else {
-                       lsm.cmd_type = LTTNG_ENABLE_EVENT_WITH_FILTER;
-               }
-       } else {
-               lsm.cmd_type = LTTNG_ENABLE_EVENT_WITH_EXCLUSION;
-       }
+       lsm.cmd_type = LTTNG_ENABLE_EVENT;
 
        memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
 
@@ -869,9 +855,8 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
        }
 
        ret = lttng_ctl_ask_sessiond_varlen(&lsm, varlen_data,
-                       LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count
-                                       + lsm.u.enable.bytecode_len,
-                       NULL);
+                       (LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count) +
+                       lsm.u.enable.bytecode_len, NULL);
 
        if (lsm.u.enable.exclusion_count != 0) {
                free(varlen_data);
This page took 0.032204 seconds and 5 git commands to generate.