Mailing List Archive

[PATCH 3/5] x86: Add usage() to print out usage message
Refactor xen-ucode tool by adding usage() to handle usage\help messages

Signed-off-by: Fouad Hilly <fouad.hilly@cloud.com>
---
tools/misc/xen-ucode.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c
index c6ae6498d659..1edcebfb9f9c 100644
--- a/tools/misc/xen-ucode.c
+++ b/tools/misc/xen-ucode.c
@@ -17,6 +17,14 @@ static xc_interface *xch;
static const char intel_id[] = "GenuineIntel";
static const char amd_id[] = "AuthenticAMD";

+static void usage(const char *name)
+{
+ printf("%s: Xen microcode updating tool\n"
+ "Usage: %s [<microcode file> | show-cpu-info]\n"
+ "\n"
+ , name, name);
+}
+
static void show_curr_cpu(FILE *f)
{
int ret;
@@ -88,9 +96,7 @@ int main(int argc, char *argv[])

if ( argc < 2 )
{
- fprintf(stderr,
- "xen-ucode: Xen microcode updating tool\n"
- "Usage: %s [<microcode file> | show-cpu-info]\n", argv[0]);
+ usage(argv[0]);
show_curr_cpu(stderr);
exit(2);
}
--
2.42.0
Re: [PATCH 3/5] x86: Add usage() to print out usage message [ In reply to ]
On 05.04.2024 14:11, Fouad Hilly wrote:
> Refactor xen-ucode tool by adding usage() to handle usage\help messages

Would be nice if you could also say why you want this.

> --- a/tools/misc/xen-ucode.c
> +++ b/tools/misc/xen-ucode.c
> @@ -17,6 +17,14 @@ static xc_interface *xch;
> static const char intel_id[] = "GenuineIntel";
> static const char amd_id[] = "AuthenticAMD";
>
> +static void usage(const char *name)
> +{
> + printf("%s: Xen microcode updating tool\n"
> + "Usage: %s [<microcode file> | show-cpu-info]\n"
> + "\n"
> + , name, name);
> +}

Besides formatting issues you also add an extra \n to the format string,
you convert the previously hard-coded xen-ucode: (which may be okay, but
wants clarifying on why it is done), ...

> @@ -88,9 +96,7 @@ int main(int argc, char *argv[])
>
> if ( argc < 2 )
> {
> - fprintf(stderr,
> - "xen-ucode: Xen microcode updating tool\n"
> - "Usage: %s [<microcode file> | show-cpu-info]\n", argv[0]);
> + usage(argv[0]);
> show_curr_cpu(stderr);
> exit(2);
> }

... and you no longer print to stderr. This being an error path, the
message ought to continue to go there; only a possible -h / --help option
would want it to go to stdout.

Jan