Fix: help message for Python agent mentions Java
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
index c4da3dfb67c50ea9cd00d6148a52192722a102d5..92ca76272bb54e78d40e432d674cc1c933f39b43 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <assert.h>
 #include <popt.h>
 #include <stdio.h>
@@ -126,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");
@@ -561,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]);
@@ -620,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) {
@@ -825,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,
@@ -833,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,
@@ -850,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,
@@ -858,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,
@@ -1124,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) {
@@ -1183,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:
This page took 0.024993 seconds and 4 git commands to generate.