@@ -202,6 +202,26 @@ update_option(const char *file, struct tep_plugin_option *option)
return ret;
}
+static struct tep_plugin_option *
+find_registered_option(const char *plugin, const char *option)
+{
+ struct registered_plugin_options *reg;
+ struct tep_plugin_option *op;
+
+ for (reg = registered_options; reg; reg = reg->next) {
+ for (op = reg->options; op->name; op++) {
+ if (plugin && strcmp(plugin, op->plugin) != 0)
+ continue;
+ if (strcmp(option, op->name) != 0)
+ continue;
+
+ return op;
+ }
+ }
+
+ return NULL;
+}
+
/**
* tep_plugin_add_options - Add a set of options by a plugin
* @name: The name of the plugin adding the options
@@ -213,6 +233,16 @@ int tep_plugin_add_options(const char *name,
struct tep_plugin_option *options)
{
struct registered_plugin_options *reg;
+ struct tep_plugin_option *option;
+
+ option = options;
+ while (option && option->name) {
+ if (!option->plugin)
+ return -EINVAL;
+ if (find_registered_option(name, option->name))
+ return -EBUSY;
+ option++;
+ }
reg = malloc(sizeof(*reg));
if (!reg)
@@ -262,26 +292,6 @@ static void parse_option_name(char **option, char **plugin)
}
}
-static struct tep_plugin_option *
-find_registered_option(const char *plugin, const char *option)
-{
- struct registered_plugin_options *reg;
- struct tep_plugin_option *op;
-
- for (reg = registered_options; reg; reg = reg->next) {
- for (op = reg->options; op->name; op++) {
- if (plugin && strcmp(plugin, op->plugin) != 0)
- continue;
- if (strcmp(option, op->name) != 0)
- continue;
-
- return op;
- }
- }
-
- return NULL;
-}
-
static int process_option(const char *plugin, const char *option, const char *val)
{
struct tep_plugin_option *op;
When loading new plugin options, check is an option with the same name and plugin is already registered. The API tep_plugin_add_options() is modified to return errors is these cases: - The "plugin" field in the option's description is not set, return -EINVAL - An option with the same name and plugin is already registered return -EBUSY Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/traceevent/event-plugin.c | 50 +++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 20 deletions(-)