Warn when exclusion names are truncated
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
index 972043eeb25f672c9ec02d9f13232c4ca80d98b1..6a536976636e6d4f5729ccc9333f6ec066da4b48 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <assert.h>
 #include <popt.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -29,6 +27,7 @@
 #include <ctype.h>
 
 #include <src/common/sessiond-comm/sessiond-comm.h>
+#include <common/compat/string.h>
 
 /* Mi dependancy */
 #include <common/mi-lttng.h>
@@ -109,9 +108,9 @@ static void usage(FILE *ofp)
        fprintf(ofp, "  -s, --session NAME       Apply to session name\n");
        fprintf(ofp, "  -c, --channel NAME       Apply to this channel\n");
        fprintf(ofp, "  -a, --all                Enable all tracepoints and syscalls\n");
-       fprintf(ofp, "  -k, --kernel             Apply for the kernel tracer\n");
+       fprintf(ofp, "  -k, --kernel             Apply to the kernel tracer\n");
        fprintf(ofp, "  -u, --userspace          Apply to the user-space tracer\n");
-       fprintf(ofp, "  -j, --jul                Apply for Java application using JUL\n");
+       fprintf(ofp, "  -j, --jul                Apply to Java application using JUL\n");
        fprintf(ofp, "  -l, --log4j              Apply for Java application using LOG4j\n");
        fprintf(ofp, "  -p, --python             Apply for Python application\n");
        fprintf(ofp, "\n");
@@ -626,9 +625,9 @@ int check_exclusion_subsets(const char *event_name,
                                char **new_exclusion_list;
 
                                /* Excluder is a proper subset of event */
-                               string = strndup(next_excluder, excluder_length);
+                               string = lttng_strndup(next_excluder, excluder_length);
                                if (!string) {
-                                       PERROR("strndup error");
+                                       PERROR("lttng_strndup error");
                                        goto error;
                                }
                                new_exclusion_list = realloc(exclusion_list,
@@ -677,6 +676,24 @@ end:
        *exclusion_list_ptr = exclusion_list;
        return ret;
 }
+
+static void warn_on_truncated_exclusion_names(char **exclusion_list,
+       int exclusion_count, int *warn)
+{
+       size_t i = 0;
+
+       for (i = 0; i < exclusion_count; ++i) {
+               const char *name = exclusion_list[i];
+               size_t len = strlen(name);
+
+               if (len >= LTTNG_SYMBOL_NAME_LEN) {
+                       WARN("Event exclusion \"%s\" will be truncated",
+                               name);
+                       *warn = 1;
+               }
+       }
+}
+
 /*
  * Enabling event using the lttng API.
  * Note: in case of error only the last error code will be return.
@@ -809,6 +826,9 @@ static int enable_events(char *session_name)
                                goto error;
                        }
                        ev.exclusion = 1;
+
+                       warn_on_truncated_exclusion_names(exclusion_list,
+                               exclusion_count, &warn);
                }
                if (!opt_filter) {
                        ret = lttng_enable_event_with_exclusions(handle,
@@ -1101,6 +1121,9 @@ static int enable_events(char *session_name)
                                if (ret == CMD_ERROR) {
                                        goto error;
                                }
+
+                               warn_on_truncated_exclusion_names(
+                                       exclusion_list, exclusion_count, &warn);
                        }
 
                        ev.loglevel_type = opt_loglevel_type;
This page took 0.024459 seconds and 4 git commands to generate.