tracing: Allow whitespace to surround hist trigger filter
authorTom Zanussi <tom.zanussi@linux.intel.com>
Tue, 16 Jan 2018 02:52:02 +0000 (20:52 -0600)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Sat, 10 Mar 2018 21:06:00 +0000 (16:06 -0500)
The existing code only allows for one space before and after the 'if'
specifying the filter for a hist trigger.  Add code to make that more
permissive as far as whitespace goes.  Specifically, we want to allow
spaces in the trigger itself now that we have additional syntax
(onmatch/onmax) where spaces are more natural e.g. spaces after commas
in param lists.

Link: http://lkml.kernel.org/r/1053090c3c308d4f431accdeb59dff4b511d4554.1516069914.git.tom.zanussi@linux.intel.com
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/trace/trace_events_hist.c

index 7bcc32a7e266a9f3c07da1fe9f246eb3e778b187..7e88daae85b6ef0334d69ae3326b342424918046 100644 (file)
@@ -5162,7 +5162,7 @@ static int event_hist_trigger_func(struct event_command *cmd_ops,
        struct synth_event *se;
        const char *se_name;
        bool remove = false;
-       char *trigger;
+       char *trigger, *p;
        int ret = 0;
 
        if (!param)
@@ -5171,10 +5171,37 @@ static int event_hist_trigger_func(struct event_command *cmd_ops,
        if (glob[0] == '!')
                remove = true;
 
-       /* separate the trigger from the filter (k:v [if filter]) */
-       trigger = strsep(&param, " \t");
-       if (!trigger)
-               return -EINVAL;
+       /*
+        * separate the trigger from the filter (k:v [if filter])
+        * allowing for whitespace in the trigger
+        */
+       p = trigger = param;
+       do {
+               p = strstr(p, "if");
+               if (!p)
+                       break;
+               if (p == param)
+                       return -EINVAL;
+               if (*(p - 1) != ' ' && *(p - 1) != '\t') {
+                       p++;
+                       continue;
+               }
+               if (p >= param + strlen(param) - strlen("if") - 1)
+                       return -EINVAL;
+               if (*(p + strlen("if")) != ' ' && *(p + strlen("if")) != '\t') {
+                       p++;
+                       continue;
+               }
+               break;
+       } while (p);
+
+       if (!p)
+               param = NULL;
+       else {
+               *(p - 1) = '\0';
+               param = strstrip(p);
+               trigger = strstrip(trigger);
+       }
 
        attrs = parse_hist_trigger_attrs(trigger);
        if (IS_ERR(attrs))