- /* Validate strings used as literals in the expression. */
- ret = filter_visitor_ir_validate_string(ctx);
- if (ret) {
- ret = -LTTNG_ERR_FILTER_INVAL;
- goto parse_error;
- }
-
- /* Validate globbing patterns in the expression. */
- ret = filter_visitor_ir_validate_globbing(ctx);
- if (ret) {
- ret = -LTTNG_ERR_FILTER_INVAL;
- goto parse_error;
- }
-
- dbg_printf("done\n");
-
- dbg_printf("Generating bytecode... ");
- fflush(stdout);
- ret = filter_visitor_bytecode_generate(ctx);
- if (ret) {
- fprintf(stderr, "Generate bytecode error\n");
- ret = -LTTNG_ERR_FILTER_INVAL;
- goto parse_error;
- }
- dbg_printf("done\n");
- dbg_printf("Size of bytecode generated: %u bytes.\n",
- bytecode_get_len(&ctx->bytecode->b));
-
- lsm->u.enable.bytecode_len = sizeof(ctx->bytecode->b)
- + bytecode_get_len(&ctx->bytecode->b);
- lsm->u.enable.expression_len = strlen(filter_expression) + 1;
-
- /* No need to keep the memory stream. */
- if (fclose(fmem) != 0) {
- PERROR("fclose");
- }
-
- *ctxp = ctx;
- return 0;
-
-parse_error:
- filter_ir_free(ctx);
- filter_parser_ctx_free(ctx);
-filter_alloc_error:
- if (fclose(fmem) != 0) {
- PERROR("fclose");
- }
-error:
- return ret;
-}
-
-/*
- * Enable event(s) for a channel, possibly with exclusions and a filter.
- * If no event name is specified, all events are enabled.
- * If no channel name is specified, the default name is used.
- * If filter expression is not NULL, the filter is set for the event.
- * If exclusion count is not zero, the exclusions are set for the event.
- * Returns size of returned session payload data or a negative error code.
- */
-int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
- struct lttng_event *ev, const char *channel_name,
- const char *original_filter_expression,
- int exclusion_count, char **exclusion_list)
-{
- struct lttcomm_session_msg lsm;
- struct lttng_dynamic_buffer send_buffer;
- int ret = 0, i, fd_to_send = -1;
- bool send_fd = false;
- unsigned int free_filter_expression = 0;
- struct filter_parser_ctx *ctx = NULL;
-
- /*
- * We have either a filter or some exclusions, so we need to set up
- * a variable-length memory block from where to send the data.
- */
- lttng_dynamic_buffer_init(&send_buffer);
-
- /*
- * Cast as non-const since we may replace the filter expression
- * by a dynamically allocated string. Otherwise, the original
- * string is not modified.
- */
- char *filter_expression = (char *) original_filter_expression;
-
- if (handle == NULL || ev == NULL) {
- ret = -LTTNG_ERR_INVALID;
- goto error;
- }
-
- /*
- * Empty filter string will always be rejected by the parser
- * anyway, so treat this corner-case early to eliminate
- * lttng_fmemopen error for 0-byte allocation.
- */
- if (filter_expression && filter_expression[0] == '\0') {
- ret = -LTTNG_ERR_INVALID;
- goto error;
- }
-
- memset(&lsm, 0, sizeof(lsm));
-
- /* If no channel name, send empty string. */
- if (channel_name == NULL) {
- lttng_ctl_copy_string(lsm.u.enable.channel_name, "",
- sizeof(lsm.u.enable.channel_name));
- } else {
- lttng_ctl_copy_string(lsm.u.enable.channel_name, channel_name,
- sizeof(lsm.u.enable.channel_name));
- }
-
- lsm.cmd_type = LTTNG_ENABLE_EVENT;
- if (ev->name[0] == '\0') {
- /* Enable all events */
- lttng_ctl_copy_string(ev->name, "*", sizeof(ev->name));
- }
-
- lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
- /* FIXME: copying non-packed struct to packed struct. */
- memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
-
- lttng_ctl_copy_string(lsm.session.name, handle->session_name,
- sizeof(lsm.session.name));
- lsm.u.enable.exclusion_count = exclusion_count;
- lsm.u.enable.bytecode_len = 0;
-