Remove dot after enable-event message
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
index 8b1215b111cfae31c2721c4a61f22211efd79d8e..6ebf89f72f757565dd0edf98f154e338c2fcae4b 100644 (file)
@@ -112,7 +112,7 @@ static struct poptOption long_options[] = {
  */
 static void usage(FILE *ofp)
 {
-       fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n");
+       fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] (-k | -u | -j | -l | -p) [OPTIONS] \n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Options:\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
@@ -514,7 +514,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]);
@@ -573,11 +576,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) {
@@ -664,10 +681,21 @@ static int enable_events(char *session_name)
                goto error;
        }
 
-       if (opt_kernel && opt_exclude) {
-               ERR("Event name exclusions are not yet implemented for kernel events");
-               ret = CMD_ERROR;
-               goto error;
+       if (opt_exclude) {
+               switch (dom.type) {
+               case LTTNG_DOMAIN_KERNEL:
+               case LTTNG_DOMAIN_JUL:
+               case LTTNG_DOMAIN_LOG4J:
+                       ERR("Event name exclusions are not yet implemented for %s events",
+                                       get_domain_str(dom.type));
+                       ret = CMD_ERROR;
+                       goto error;
+               case LTTNG_DOMAIN_UST:
+                       /* Exclusions supported */
+                       break;
+               default:
+                       assert(0);
+               }
        }
 
        channel_name = opt_channel_name;
@@ -743,6 +771,16 @@ static int enable_events(char *session_name)
                                                        print_channel_name(channel_name), session_name);
                                        warn = 1;
                                        break;
+                               case LTTNG_ERR_TRACE_ALREADY_STARTED:
+                               {
+                                       const char *msg = "The command tried to enable an event in a new domain for a session that has already been started once.";
+                                       ERR("Events: %s (channel %s, session %s)",
+                                                       msg,
+                                                       print_channel_name(channel_name),
+                                                       session_name);
+                                       error = 1;
+                                       break;
+                               }
                                default:
                                        ERR("Events: %s (channel %s, session %s)",
                                                        lttng_strerror(ret),
@@ -760,6 +798,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,
@@ -768,6 +812,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,
@@ -785,6 +835,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,
@@ -793,6 +849,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,
@@ -820,6 +882,16 @@ static int enable_events(char *session_name)
                                                print_channel_name(channel_name), session_name);
                                        warn = 1;
                                        break;
+                               case LTTNG_ERR_TRACE_ALREADY_STARTED:
+                               {
+                                       const char *msg = "The command tried to enable an event in a new domain for a session that has already been started once.";
+                                       ERR("All events: %s (channel %s, session %s, filter \'%s\')",
+                                                       msg,
+                                                       print_channel_name(channel_name),
+                                                       session_name, opt_filter);
+                                       error = 1;
+                                       break;
+                               }
                                default:
                                        ERR("All events: %s (channel %s, session %s, filter \'%s\')",
                                                        lttng_strerror(command_ret),
@@ -1045,6 +1117,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) {
@@ -1055,6 +1132,17 @@ static int enable_events(char *session_name)
                                                        print_channel_name(channel_name), session_name);
                                        warn = 1;
                                        break;
+                               case LTTNG_ERR_TRACE_ALREADY_STARTED:
+                               {
+                                       const char *msg = "The command tried to enable an event in a new domain for a session that has already been started once.";
+                                       ERR("Event %s%s: %s (channel %s, session %s)", event_name,
+                                                       exclusion_string,
+                                                       msg,
+                                                       print_channel_name(channel_name),
+                                                       session_name);
+                                       error = 1;
+                                       break;
+                               }
                                default:
                                        ERR("Event %s%s: %s (channel %s, session %s)", event_name,
                                                        exclusion_string,
@@ -1068,17 +1156,28 @@ static int enable_events(char *session_name)
                                }
                                error_holder = command_ret;
                        } else {
-                               /* So we don't print the default channel name for agent domain. */
-                               if (dom.type == LTTNG_DOMAIN_JUL ||
-                                               dom.type == LTTNG_DOMAIN_LOG4J) {
-                                       MSG("%s event %s%s enabled.",
-                                                       get_domain_str(dom.type), event_name,
-                                                       exclusion_string);
-                               } else {
+                               switch (dom.type) {
+                               case LTTNG_DOMAIN_KERNEL:
+                               case LTTNG_DOMAIN_UST:
                                        MSG("%s event %s%s created in channel %s",
-                                                       get_domain_str(dom.type), event_name,
-                                                       exclusion_string,
-                                                       print_channel_name(channel_name));
+                                               get_domain_str(dom.type),
+                                               event_name,
+                                               exclusion_string,
+                                               print_channel_name(channel_name));
+                                       break;
+                               case LTTNG_DOMAIN_JUL:
+                               case LTTNG_DOMAIN_LOG4J:
+                                       /*
+                                        * Don't print the default channel
+                                        * name for agent domains.
+                                        */
+                                       MSG("%s event %s%s enabled",
+                                               get_domain_str(dom.type),
+                                               event_name,
+                                               exclusion_string);
+                                       break;
+                               default:
+                                       assert(0);
                                }
                        }
                        free(exclusion_string);
@@ -1093,7 +1192,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:
@@ -1104,6 +1207,17 @@ static int enable_events(char *session_name)
                                                print_channel_name(channel_name), session_name);
                                        warn = 1;
                                        break;
+                               case LTTNG_ERR_TRACE_ALREADY_STARTED:
+                               {
+                                       const char *msg = "The command tried to enable an event in a new domain for a session that has already been started once.";
+                                       ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev.name,
+                                                       exclusion_string,
+                                                       msg,
+                                                       print_channel_name(channel_name),
+                                                       session_name, opt_filter);
+                                       error = 1;
+                                       break;
+                               }
                                default:
                                        ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev.name,
                                                        exclusion_string,
This page took 0.027252 seconds and 4 git commands to generate.