qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: "demin.han" <demin.han@starfivetech.com>
Cc: qemu-devel@nongnu.org,  erdnaxe@crans.org,
	 ma.mandourr@gmail.com, pierrick.bouvier@linaro.org
Subject: Re: [PATCH] plugins: add plugin API to get args passed to binary
Date: Thu, 09 Jan 2025 11:58:59 +0000	[thread overview]
Message-ID: <87v7uo8ags.fsf@draig.linaro.org> (raw)
In-Reply-To: <20241101090032.1413255-1-demin.han@starfivetech.com> (demin han's message of "Fri, 1 Nov 2024 17:00:32 +0800")

"demin.han" <demin.han@starfivetech.com> writes:

> Why we need args?
> When plugin outputs log files, only binary path can't distinguish multiple
> runs if the binary passed with different args.
> This is bad for CI using plugin.

New APIs should come with an example use case for testing. However for
this use case why isn't the plugin using getpid() or gettid() a suitable
solution?

Some additional comments bellow...

> Signed-off-by: demin.han <demin.han@starfivetech.com>
> ---
>  include/qemu/qemu-plugin.h   | 11 +++++++++++
>  plugins/api.c                | 16 ++++++++++++++++
>  plugins/qemu-plugins.symbols |  1 +
>  3 files changed, 28 insertions(+)
>
> diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
> index 622c9a0232..daf75c9f5a 100644
> --- a/include/qemu/qemu-plugin.h
> +++ b/include/qemu/qemu-plugin.h
> @@ -837,6 +837,17 @@ bool qemu_plugin_bool_parse(const char *name, const char *val, bool *ret);
>  QEMU_PLUGIN_API
>  const char *qemu_plugin_path_to_binary(void);
>  
> +/**
> + * qemu_plugin_argv_to_binary() - argv to binary file being executed
> + *
> + * Return a string array representing the argv to the binary. For user-mode
> + * this is the main executable's argv. For system emulation we currently
> + * return NULL.

Maybe more explicit:

qemu_plugin_get_user_argv() and be clear it is user mode only.

Although I suspect a qemu_plugin_get_user_env() might be a more useful
helper depending on the use case.

> The user should g_free() the string array once no longer
> + * needed.
> + */
> +QEMU_PLUGIN_API
> +const char **qemu_plugin_argv_to_binary(void);
> +
>  /**
>   * qemu_plugin_start_code() - returns start of text segment
>   *
> diff --git a/plugins/api.c b/plugins/api.c
> index 24ea64e2de..fa2735db03 100644
> --- a/plugins/api.c
> +++ b/plugins/api.c
> @@ -485,6 +485,22 @@ const char *qemu_plugin_path_to_binary(void)
>      return path;
>  }
>  
> +const char **qemu_plugin_argv_to_binary(void)
> +{
> +    const char **argv = NULL;
> +#ifdef CONFIG_USER_ONLY
> +    int i, argc;
> +    TaskState *ts = get_task_state(current_cpu);
> +    argc = ts->bprm->argc;
> +    argv = g_malloc(sizeof(char *) * (argc + 1));

 argv = g_new0(char *, argc + 1);

> +    for (i = 0; i < argc; ++i) {
> +        argv[i] = g_strdup(ts->bprm->argv[i]);
> +    }
> +    argv[argc] = NULL;

Allows you to drop this as well.

> +#endif
> +    return argv;
> +}
> +
>  uint64_t qemu_plugin_start_code(void)
>  {
>      uint64_t start = 0;
> diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols
> index 032661f9ea..532582effe 100644
> --- a/plugins/qemu-plugins.symbols
> +++ b/plugins/qemu-plugins.symbols
> @@ -1,4 +1,5 @@
>  {
> +  qemu_plugin_argv_to_binary;
>    qemu_plugin_bool_parse;
>    qemu_plugin_end_code;
>    qemu_plugin_entry_code;

You can drop the symbols now we autogenerate them.

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  parent reply	other threads:[~2025-01-09 11:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-01  9:00 [PATCH] plugins: add plugin API to get args passed to binary demin.han
2024-11-01 18:18 ` Pierrick Bouvier
2025-01-09 11:58 ` Alex Bennée [this message]
2025-01-10  1:24   ` Demin Han
  -- strict thread matches above, loose matches on Subject: below --
2024-11-02  5:10 Demin Han
2024-11-04 21:21 ` Pierrick Bouvier
2024-11-05  2:29   ` Demin Han
2024-11-05  2:49     ` Pierrick Bouvier
2024-11-05  3:31       ` Demin Han
2024-11-05  3:44         ` Pierrick Bouvier
2024-11-05  3:53           ` Demin Han
2024-11-05  4:28             ` Pierrick Bouvier

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=87v7uo8ags.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=demin.han@starfivetech.com \
    --cc=erdnaxe@crans.org \
    --cc=ma.mandourr@gmail.com \
    --cc=pierrick.bouvier@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 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).