All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mahmoud Mandour <ma.mandourr@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: [RFC PATCH] Subject: [RFC PATCH] plugins: Passed the parsed arguments directly to plugins
Date: Wed, 23 Jun 2021 17:55:53 +0200	[thread overview]
Message-ID: <20210623155553.481099-1-ma.mandourr@gmail.com> (raw)

Arguments were passed to plugins in the following form:
    -plugin path/to/plugin,arg="positional_arg=value",arg="second_arg"

This patch removes the need for "arg" so that the argument name itself
is now expected and passed directly to the plugin.

Now options can be passed in the following manner:
    -plugin path/to/plugin,positional_arg=value,second_arg

Since short boolean arguments are deprecated, passing an argument that
takes no value will trigger a warning saying that the user should use a
full "arg_name=on" instead of just "arg_name". In either case, the
argument is passed to the plugin as only the name, omitting the "=on"
part.

Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
---
 plugins/loader.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/plugins/loader.c b/plugins/loader.c
index 05df40398d..7f32b8c8bd 100644
--- a/plugins/loader.c
+++ b/plugins/loader.c
@@ -94,6 +94,7 @@ static int plugin_add(void *opaque, const char *name, const char *value,
 {
     struct qemu_plugin_parse_arg *arg = opaque;
     struct qemu_plugin_desc *p;
+    char *full_arg;
 
     if (strcmp(name, "file") == 0) {
         if (strcmp(value, "") == 0) {
@@ -107,7 +108,7 @@ static int plugin_add(void *opaque, const char *name, const char *value,
             QTAILQ_INSERT_TAIL(arg->head, p, entry);
         }
         arg->curr = p;
-    } else if (strcmp(name, "arg") == 0) {
+    } else {
         if (arg->curr == NULL) {
             error_setg(errp, "missing earlier '-plugin file=' option");
             return 1;
@@ -115,9 +116,12 @@ static int plugin_add(void *opaque, const char *name, const char *value,
         p = arg->curr;
         p->argc++;
         p->argv = g_realloc_n(p->argv, p->argc, sizeof(char *));
-        p->argv[p->argc - 1] = g_strdup(value);
-    } else {
-        error_setg(errp, "-plugin: unexpected parameter '%s'; ignored", name);
+        if (strcmp(value, "on")) {
+            full_arg = g_strdup_printf("%s=%s", name, value);
+        } else {
+            full_arg = g_strdup(name);
+        }
+        p->argv[p->argc - 1] = full_arg;
     }
     return 0;
 }
-- 
2.25.1



             reply	other threads:[~2021-06-23 15:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23 15:55 Mahmoud Mandour [this message]
2021-06-25 11:38 ` [RFC PATCH] Subject: [RFC PATCH] plugins: Passed the parsed arguments directly to plugins Alex Bennée

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=20210623155553.481099-1-ma.mandourr@gmail.com \
    --to=ma.mandourr@gmail.com \
    --cc=alex.bennee@linaro.org \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.