- struct lttng_event *ev = NULL;
- struct lttng_event_exclusion *exclusion = NULL;
- struct lttng_filter_bytecode *bytecode = NULL;
- char *filter_expression = NULL;
-
- /* 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;
- }
-
- 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;
- }
- }
-
- /* Get filter expression from client. */
- if (cmd_ctx->lsm->u.enable.expression_len > 0) {
- size_t expression_len =
- cmd_ctx->lsm->u.enable.expression_len;
-
- if (expression_len > LTTNG_FILTER_MAX_LEN) {
- ret = LTTNG_ERR_FILTER_INVAL;
- free(exclusion);
- goto error;
- }
-
- filter_expression = zmalloc(expression_len);
- if (!filter_expression) {
- free(exclusion);
- ret = LTTNG_ERR_FILTER_NOMEM;
- goto error;
- }
-
- /* Receive var. len. data */
- DBG("Receiving var len filter's expression from client ...");
- ret = lttcomm_recv_unix_sock(sock, filter_expression,
- expression_len);
- if (ret <= 0) {
- DBG("Nothing recv() from client var len data... continuing");
- *sock_error = 1;
- free(filter_expression);
- free(exclusion);
- ret = LTTNG_ERR_FILTER_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(filter_expression);
- free(exclusion);
- goto error;
- }
-
- bytecode = zmalloc(bytecode_len);
- if (!bytecode) {
- free(filter_expression);
- 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 var len data... continuing");
- *sock_error = 1;
- free(filter_expression);
- free(bytecode);
- free(exclusion);
- ret = LTTNG_ERR_FILTER_INVAL;
- goto error;
- }
-
- if ((bytecode->len + sizeof(*bytecode)) != bytecode_len) {
- free(filter_expression);
- free(bytecode);
- free(exclusion);
- ret = LTTNG_ERR_FILTER_INVAL;
- goto error;
- }
- }
-
- ev = lttng_event_copy(&cmd_ctx->lsm->u.enable.event);
- if (!ev) {
- DBG("Failed to copy event: %s",
- cmd_ctx->lsm->u.enable.event.name);
- free(filter_expression);
- free(bytecode);
- free(exclusion);
- ret = LTTNG_ERR_NOMEM;
+ struct lttng_event *event;
+ char *filter_expression;
+ struct lttng_event_exclusion *exclusions;
+ struct lttng_bytecode *bytecode;
+ const enum lttng_error_code ret_code = receive_lttng_event(
+ cmd_ctx, *sock, sock_error, &event,
+ &filter_expression, &bytecode, &exclusions);
+
+ if (ret_code != LTTNG_OK) {
+ ret = (int) ret_code;