Message ID | 20200207130453.16666-4-philmd@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Make MachineClass::is_default boolean, refuse multiple default machines | expand |
On Fri, Feb 07, 2020 at 02:04:53PM +0100, Philippe Mathieu-Daudé wrote: > It would be confusing to have multiple default machines. > Abort if this ever occurs. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> > --- > v2: Use assert() instead of human friendly message (Marc-André) > > Cc: Marc-André Lureau <marcandre.lureau@gmail.com> > Cc: Laurent Vivier <laurent@vivier.eu> Is it really worth adding counting logic just so we can assert? There are a bunch of other places that deal with default, like qmp query machines and find_default_machine. > --- > vl.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/vl.c b/vl.c > index 7dcb0879c4..b3e0f7af25 100644 > --- a/vl.c > +++ b/vl.c > @@ -2354,6 +2354,8 @@ static MachineClass *machine_parse(const char *name, GSList *machines) > GSList *el; > > if (is_help_option(name)) { > + int default_count = 0; > + > printf("Supported machines are:\n"); > machines = g_slist_sort(machines, machine_class_cmp); > for (el = machines; el; el = el->next) { > @@ -2364,7 +2366,9 @@ static MachineClass *machine_parse(const char *name, GSList *machines) > printf("%-20s %s%s%s\n", mc->name, mc->desc, > mc->is_default ? " (default)" : "", > mc->deprecation_reason ? " (deprecated)" : ""); > + default_count += !!mc->is_default; > } > + assert(default_count <= 1); > exit(0); > } > > -- > 2.21.1
diff --git a/vl.c b/vl.c index 7dcb0879c4..b3e0f7af25 100644 --- a/vl.c +++ b/vl.c @@ -2354,6 +2354,8 @@ static MachineClass *machine_parse(const char *name, GSList *machines) GSList *el; if (is_help_option(name)) { + int default_count = 0; + printf("Supported machines are:\n"); machines = g_slist_sort(machines, machine_class_cmp); for (el = machines; el; el = el->next) { @@ -2364,7 +2366,9 @@ static MachineClass *machine_parse(const char *name, GSList *machines) printf("%-20s %s%s%s\n", mc->name, mc->desc, mc->is_default ? " (default)" : "", mc->deprecation_reason ? " (deprecated)" : ""); + default_count += !!mc->is_default; } + assert(default_count <= 1); exit(0); }
It would be confusing to have multiple default machines. Abort if this ever occurs. Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> --- v2: Use assert() instead of human friendly message (Marc-André) Cc: Marc-André Lureau <marcandre.lureau@gmail.com> Cc: Laurent Vivier <laurent@vivier.eu> --- vl.c | 4 ++++ 1 file changed, 4 insertions(+)