Preben Guldberg writes:

> Thanks to Dave, Theo and Klemens for accepting my previous patch
>
> In other tests, I noticed the following error:
>
>     % vmctl stop -a testvm
>     vmctl: invalid id: (null)
>
> The patch below addresses an off-by-one error reading argv when
> generating the error message.
>
> I personally find it clearer if the condition of mixing -a with an id
> is highlighted. I included a suggestion in the patch below.
>
> Index: usr.sbin/vmctl/main.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/vmctl/main.c,v
> retrieving revision 1.62
> diff -u -p -u -p -r1.62 main.c
> --- usr.sbin/vmctl/main.c     3 Jan 2020 05:32:00 -0000       1.62
> +++ usr.sbin/vmctl/main.c     12 Mar 2021 11:23:26 -0000
> @@ -961,7 +961,7 @@ ctl_stop(struct parse_result *res, int a
>       /* VM id is only expected without the -a flag */
>       if ((res->action != CMD_STOPALL && ret == -1) ||
>           (res->action == CMD_STOPALL && ret != -1))
> -             errx(1, "invalid id: %s", argv[1]);
> +             errx(1, "invalid use of id with -a: %s", argv[0]);

Since -a and providing an id are mutually exclusive, I think it's more
helpful to print usage information via ctl_usage(res->ctl). From the
usage details, it's self explanatory what's wrong.

  usage:  vmctl [-v] stop [-fw] [id | -a]

>
>       return (vmmaction(res));
>  }

Reply via email to