X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fenable_events.c;h=92ca76272bb54e78d40e432d674cc1c933f39b43;hp=5ef349097c5622d6e8abc85521e4ae59e937bf95;hb=23171d8c7604c5278c59a22cc6d4a7dd732cd8ca;hpb=6c1c0768320135c6936c371b09731851b508c023 diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 5ef349097..92ca76272 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -127,7 +127,7 @@ static void usage(FILE *ofp) fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); fprintf(ofp, " -j, --jul Apply for Java application using JUL\n"); fprintf(ofp, " -l, --log4j Apply for Java application using LOG4j\n"); - fprintf(ofp, " -p, --python Apply for Java application using LOG4j\n"); + fprintf(ofp, " -p, --python Apply for Python application\n"); fprintf(ofp, "\n"); fprintf(ofp, "Event options:\n"); fprintf(ofp, " --tracepoint Tracepoint event (default)\n"); @@ -562,7 +562,10 @@ char *print_exclusions(int count, char **names) /* add length of preamble + one for NUL - one for last (missing) comma */ length += strlen(preamble); - ret = malloc(length); + ret = zmalloc(length); + if (!ret) { + return NULL; + } strncpy(ret, preamble, length); for (i = 0; i < count; i++) { strcat(ret, names[i]); @@ -621,11 +624,25 @@ int check_exclusion_subsets(const char *event_name, goto error; } if (e == '*') { + char *string; + char **new_exclusion_list; + /* Excluder is a proper subset of event */ + string = strndup(next_excluder, excluder_length); + if (!string) { + PERROR("strndup error"); + goto error; + } + new_exclusion_list = realloc(exclusion_list, + sizeof(char **) * (exclusion_count + 1)); + if (!new_exclusion_list) { + PERROR("realloc"); + free(string); + goto error; + } + exclusion_list = new_exclusion_list; exclusion_count++; - exclusion_list = realloc(exclusion_list, sizeof(char **) * exclusion_count); - exclusion_list[exclusion_count - 1] = strndup(next_excluder, excluder_length); - + exclusion_list[exclusion_count - 1] = string; break; } if (x != e) { @@ -826,6 +843,12 @@ static int enable_events(char *session_name) case LTTNG_EVENT_TRACEPOINT: if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); + + if (!exclusion_string) { + PERROR("Cannot allocate exclusion_string"); + error = 1; + goto end; + } MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s", get_domain_str(dom.type), exclusion_string, @@ -834,6 +857,12 @@ static int enable_events(char *session_name) free(exclusion_string); } else { char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); + + if (!exclusion_string) { + PERROR("Cannot allocate exclusion_string"); + error = 1; + goto end; + } MSG("All %s tracepoints%s are enabled in channel %s", get_domain_str(dom.type), exclusion_string, @@ -851,6 +880,12 @@ static int enable_events(char *session_name) case LTTNG_EVENT_ALL: if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); + + if (!exclusion_string) { + PERROR("Cannot allocate exclusion_string"); + error = 1; + goto end; + } MSG("All %s events%s are enabled in channel %s for loglevel %s", get_domain_str(dom.type), exclusion_string, @@ -859,6 +894,12 @@ static int enable_events(char *session_name) free(exclusion_string); } else { char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); + + if (!exclusion_string) { + PERROR("Cannot allocate exclusion_string"); + error = 1; + goto end; + } MSG("All %s events%s are enabled in channel %s", get_domain_str(dom.type), exclusion_string, @@ -1125,6 +1166,11 @@ static int enable_events(char *session_name) &ev, channel_name, NULL, exclusion_count, exclusion_list); exclusion_string = print_exclusions(exclusion_count, exclusion_list); + if (!exclusion_string) { + PERROR("Cannot allocate exclusion_string"); + error = 1; + goto end; + } if (command_ret < 0) { /* Turn ret to positive value to handle the positive error code */ switch (-command_ret) { @@ -1184,7 +1230,11 @@ static int enable_events(char *session_name) command_ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name, opt_filter, exclusion_count, exclusion_list); exclusion_string = print_exclusions(exclusion_count, exclusion_list); - + if (!exclusion_string) { + PERROR("Cannot allocate exclusion_string"); + error = 1; + goto end; + } if (command_ret < 0) { switch (-command_ret) { case LTTNG_ERR_FILTER_EXIST: