Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib traceevent: Make plugin options either string or boolean

When a plugin option is defined, by default it is a boolean (true or false).

If the option is something else, then it needs to set its "value" field to
a default string other than NULL (can be just "").

If the value is not set then the option is considered boolean, and the
updating of the option value will be handled accordingly.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150324135923.308372986@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Steven Rostedt and committed by
Arnaldo Carvalho de Melo
5dbcfd93 2771984c

+59 -7
+5 -1
tools/lib/traceevent/event-parse.h
··· 116 116 char *name; 117 117 char *plugin_alias; 118 118 char *description; 119 - char *value; 119 + const char *value; 120 120 void *priv; 121 121 int set; 122 122 }; ··· 153 153 * 154 154 * .plugin_alias is used to give a shorter name to access 155 155 * the vairable. Useful if a plugin handles more than one event. 156 + * 157 + * If .value is not set, then it is considered a boolean and only 158 + * .set will be processed. If .value is defined, then it is considered 159 + * a string option and .set will be ignored. 156 160 * 157 161 * PEVENT_PLUGIN_ALIAS: (optional) 158 162 * The name to use for finding options (uses filename if not defined)
+54 -6
tools/lib/traceevent/event-plugin.c
··· 18 18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 19 */ 20 20 21 + #include <ctype.h> 21 22 #include <stdio.h> 22 23 #include <string.h> 23 24 #include <dlfcn.h> ··· 49 48 char *name; 50 49 void *handle; 51 50 }; 51 + 52 + static void lower_case(char *str) 53 + { 54 + if (!str) 55 + return; 56 + for (; *str; str++) 57 + *str = tolower(*str); 58 + } 59 + 60 + static int update_option_value(struct pevent_plugin_option *op, const char *val) 61 + { 62 + char *op_val; 63 + 64 + if (!val) { 65 + /* toggle, only if option is boolean */ 66 + if (op->value) 67 + /* Warn? */ 68 + return 0; 69 + op->set ^= 1; 70 + return 0; 71 + } 72 + 73 + /* 74 + * If the option has a value then it takes a string 75 + * otherwise the option is a boolean. 76 + */ 77 + if (op->value) { 78 + op->value = val; 79 + return 0; 80 + } 81 + 82 + /* Option is boolean, must be either "1", "0", "true" or "false" */ 83 + 84 + op_val = strdup(val); 85 + if (!op_val) 86 + return -1; 87 + lower_case(op_val); 88 + 89 + if (strcmp(val, "1") == 0 || strcmp(val, "true") == 0) 90 + op->set = 1; 91 + else if (strcmp(val, "0") == 0 || strcmp(val, "false") == 0) 92 + op->set = 0; 93 + free(op_val); 94 + 95 + return 0; 96 + } 52 97 53 98 /** 54 99 * traceevent_plugin_list_options - get list of plugin options ··· 167 120 { 168 121 struct trace_plugin_options *op; 169 122 char *plugin; 123 + int ret = 0; 170 124 171 125 if (option->plugin_alias) { 172 126 plugin = strdup(option->plugin_alias); ··· 192 144 if (strcmp(op->option, option->name) != 0) 193 145 continue; 194 146 195 - option->value = op->value; 196 - option->set ^= 1; 197 - goto out; 147 + ret = update_option_value(option, op->value); 148 + if (ret) 149 + goto out; 150 + break; 198 151 } 199 152 200 153 /* first look for unnamed options */ ··· 205 156 if (strcmp(op->option, option->name) != 0) 206 157 continue; 207 158 208 - option->value = op->value; 209 - option->set ^= 1; 159 + ret = update_option_value(option, op->value); 210 160 break; 211 161 } 212 162 213 163 out: 214 164 free(plugin); 215 - return 0; 165 + return ret; 216 166 } 217 167 218 168 /**