vl: Abort if multiple machines are registered as default
authorPhilippe Mathieu-Daudé <philmd@redhat.com>
Fri, 7 Feb 2020 16:19:48 +0000 (17:19 +0100)
committerEduardo Habkost <ehabkost@redhat.com>
Fri, 28 Feb 2020 19:57:19 +0000 (14:57 -0500)
It would be confusing to have multiple default machines.
Abort if this ever occurs.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200207161948.15972-4-philmd@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Tested-by: Laurent Vivier <laurent@vivier.eu>
softmmu/vl.c

index 705ee6f841e4c06ed6fa77c3fa0eccd3d2490966..5549f4b619861f2e275537f26f52bad9bc0be04b 100644 (file)
@@ -1163,16 +1163,18 @@ static MachineClass *find_machine(const char *name, GSList *machines)
 static MachineClass *find_default_machine(GSList *machines)
 {
     GSList *el;
+    MachineClass *default_machineclass = NULL;
 
     for (el = machines; el; el = el->next) {
         MachineClass *mc = el->data;
 
         if (mc->is_default) {
-            return mc;
+            assert(default_machineclass == NULL && "Multiple default machines");
+            default_machineclass = mc;
         }
     }
 
-    return NULL;
+    return default_machineclass;
 }
 
 static int machine_help_func(QemuOpts *opts, MachineState *machine)