From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 3/7] trace-cmd,libtraceevent: Check for plugin options duplication
Date: Wed, 22 Jan 2020 16:59:58 +0200 [thread overview]
Message-ID: <20200122150002.763233-4-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20200122150002.763233-1-tz.stoyanov@gmail.com>
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(-)
diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c
index 8c48ccf..e53b09c 100644
--- a/lib/traceevent/event-plugin.c
+++ b/lib/traceevent/event-plugin.c
@@ -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;
--
2.24.1
next prev parent reply other threads:[~2020-01-22 15:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-22 14:59 [PATCH 0/7] trace-cmd,libtraceevent: Rework of plugin options APIs Tzvetomir Stoyanov (VMware)
2020-01-22 14:59 ` [PATCH 1/7] trace-cmd,libtraceevent: Plugin options rework Tzvetomir Stoyanov (VMware)
2020-01-22 14:59 ` [PATCH 2/7] trace-cmd,libtraceevent: Remove TEP_PLUGIN_OPTIONS Tzvetomir Stoyanov (VMware)
2020-01-22 14:59 ` Tzvetomir Stoyanov (VMware) [this message]
2020-01-22 14:59 ` [PATCH 4/7] trace-cmd,libtraceevent: Check for plugin duplication Tzvetomir Stoyanov (VMware)
2020-01-22 15:00 ` [PATCH 5/7] trace-cmd,libtraceevent: Remove API for plugin options print Tzvetomir Stoyanov (VMware)
2020-01-22 15:00 ` [PATCH 6/7] trace-cmd,libtraceevent: Remove API for plugin print Tzvetomir Stoyanov (VMware)
2020-01-22 15:00 ` [PATCH 7/7] trace-cmd, kernelshark, libtraceevent: Changed tep_plugin_add_option() API Tzvetomir Stoyanov (VMware)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200122150002.763233-4-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).