X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;h=7d06c7a0cb41b8f3396e4460c92c25afbc501d8b;hb=8f0044bfed9f5ca51eab51478f483f92cc8f84a7;hp=21173ca8e3f8982bc2c53d5c672d82fe6d764fdc;hpb=93deb080343dfcc1fafdea1301c600763b3a89aa;p=lttng-tools.git diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 21173ca8e..7d06c7a0c 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -673,36 +673,8 @@ int lttng_add_context(struct lttng_handle *handle, int lttng_enable_event(struct lttng_handle *handle, struct lttng_event *ev, const char *channel_name) { - struct lttcomm_session_msg lsm; - - if (handle == NULL || ev == NULL) { - return -LTTNG_ERR_INVALID; - } - - 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)); - } - - lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain); - - if (ev->name[0] != '\0') { - lsm.cmd_type = LTTNG_ENABLE_EVENT; - } else { - lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT; - } - 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)); - - return lttng_ctl_ask_sessiond(&lsm, NULL); + return lttng_enable_event_with_exclusions(handle, ev, channel_name, + NULL, 0, NULL); } /* @@ -715,143 +687,8 @@ int lttng_enable_event_with_filter(struct lttng_handle *handle, struct lttng_event *event, const char *channel_name, const char *filter_expression) { - struct lttcomm_session_msg lsm; - struct filter_parser_ctx *ctx; - FILE *fmem; - int ret = 0; - - if (!filter_expression) { - /* - * Fall back to normal event enabling if no filter - * specified. - */ - return lttng_enable_event(handle, event, channel_name); - } - - /* - * 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 (handle == NULL || filter_expression[0] == '\0') { - return -LTTNG_ERR_INVALID; - } - - /* - * casting const to non-const, as the underlying function will - * use it in read-only mode. - */ - fmem = lttng_fmemopen((void *) filter_expression, - strlen(filter_expression), "r"); - if (!fmem) { - fprintf(stderr, "Error opening memory as stream\n"); - return -LTTNG_ERR_FILTER_NOMEM; - } - ctx = filter_parser_ctx_alloc(fmem); - if (!ctx) { - fprintf(stderr, "Error allocating parser\n"); - ret = -LTTNG_ERR_FILTER_NOMEM; - goto alloc_error; - } - ret = filter_parser_ctx_append_ast(ctx); - if (ret) { - fprintf(stderr, "Parse error\n"); - ret = -LTTNG_ERR_FILTER_INVAL; - goto parse_error; - } - ret = filter_visitor_set_parent(ctx); - if (ret) { - fprintf(stderr, "Set parent error\n"); - ret = -LTTNG_ERR_FILTER_INVAL; - goto parse_error; - } - if (print_xml) { - ret = filter_visitor_print_xml(ctx, stdout, 0); - if (ret) { - fflush(stdout); - fprintf(stderr, "XML print error\n"); - ret = -LTTNG_ERR_FILTER_INVAL; - goto parse_error; - } - } - - dbg_printf("Generating IR... "); - fflush(stdout); - ret = filter_visitor_ir_generate(ctx); - if (ret) { - fprintf(stderr, "Generate IR error\n"); - ret = -LTTNG_ERR_FILTER_INVAL; - goto parse_error; - } - dbg_printf("done\n"); - - dbg_printf("Validating IR... "); - fflush(stdout); - ret = filter_visitor_ir_check_binary_op_nesting(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)); - - memset(&lsm, 0, sizeof(lsm)); - - lsm.cmd_type = LTTNG_ENABLE_EVENT_WITH_FILTER; - - /* 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)); - } - - /* Copy event name */ - if (event) { - memcpy(&lsm.u.enable.event, event, sizeof(lsm.u.enable.event)); - } - - lsm.u.enable.bytecode_len = sizeof(ctx->bytecode->b) - + bytecode_get_len(&ctx->bytecode->b); - - lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain); - - lttng_ctl_copy_string(lsm.session.name, handle->session_name, - sizeof(lsm.session.name)); - - ret = lttng_ctl_ask_sessiond_varlen(&lsm, &ctx->bytecode->b, - lsm.u.enable.bytecode_len, NULL); - - filter_bytecode_free(ctx); - filter_ir_free(ctx); - filter_parser_ctx_free(ctx); - if (fclose(fmem) != 0) { - perror("fclose"); - } - return ret; - -parse_error: - filter_bytecode_free(ctx); - filter_ir_free(ctx); - filter_parser_ctx_free(ctx); -alloc_error: - if (fclose(fmem) != 0) { - perror("fclose"); - } - return ret; + return lttng_enable_event_with_exclusions(handle, event, channel_name, + filter_expression, 0, NULL); } /* @@ -896,23 +733,13 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, sizeof(lsm.u.enable.channel_name)); } - 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; - } + if (ev->name[0] != '\0') { + lsm.cmd_type = LTTNG_ENABLE_EVENT; } else { - lsm.cmd_type = LTTNG_ENABLE_EVENT_WITH_EXCLUSION; + lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT; } + lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain); memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event)); lttng_ctl_copy_string(lsm.session.name, handle->session_name, @@ -1032,9 +859,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); @@ -1732,7 +1558,7 @@ int lttng_create_session_live(const char *name, const char *url, lttng_ctl_copy_string(lsm.session.name, name, sizeof(lsm.session.name)); size = uri_parse_str_urls(url, NULL, &uris); - if (size < 0) { + if (size <= 0) { ret = -LTTNG_ERR_INVALID; goto end; }