X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;h=29f8a10d4d65f7d2295a289793789e520f79ed08;hb=e9efbcd3dd835cec567ba8295a8906ed56c8bf0b;hp=921db6f598fb30195398750f9a906e355e36707e;hpb=347c5ab5500e49fcd356a7e000f44ebce633e1d4;p=lttng-tools.git diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 921db6f59..29f8a10d4 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -753,14 +753,21 @@ end: */ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, struct lttng_event *ev, const char *channel_name, - const char *filter_expression, + const char *original_filter_expression, int exclusion_count, char **exclusion_list) { struct lttcomm_session_msg lsm; - char *varlen_data, *jul_filter = NULL; + char *varlen_data; int ret = 0; struct filter_parser_ctx *ctx = NULL; FILE *fmem = NULL; + /* + * 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; + int free_filter_expression = 0; if (handle == NULL || ev == NULL) { return -LTTNG_ERR_INVALID; @@ -817,10 +824,20 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, /* Parse filter expression */ if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL) { if (handle->domain.type == LTTNG_DOMAIN_JUL) { + char *jul_filter; + /* Setup JUL filter if needed. */ - filter_expression = set_jul_filter(filter_expression, ev); - if (!filter_expression) { + jul_filter = set_jul_filter(filter_expression, ev); + if (!jul_filter && !filter_expression) { + /* No JUL and no filter, just skip everything below. */ goto ask_sessiond; + } else { + /* + * With a JUL filter, the original filter has been added to it + * thus replace the filter expression. + */ + filter_expression = jul_filter; + free_filter_expression = 1; } } @@ -832,7 +849,6 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, strlen(filter_expression), "r"); if (!fmem) { fprintf(stderr, "Error opening memory as stream\n"); - free(jul_filter); return -LTTNG_ERR_FILTER_NOMEM; } ctx = filter_parser_ctx_alloc(fmem); @@ -942,8 +958,15 @@ varlen_alloc_error: if (fclose(fmem) != 0) { perror("fclose"); } + if (free_filter_expression) { + /* + * The filter expression has been replaced and must be + * freed as it is not the original filter expression + * received as a parameter. + */ + free(filter_expression); + } } - free(jul_filter); return ret; parse_error: @@ -954,7 +977,6 @@ filter_alloc_error: if (fclose(fmem) != 0) { perror("fclose"); } - free(jul_filter); return ret; ask_sessiond: