]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Use proper enum types for 'onReboot', 'onPoweroff', 'onCrash', and 'onLockFailure'
authorPeter Krempa <pkrempa@redhat.com>
Tue, 21 Jul 2026 08:21:50 +0000 (10:21 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Jul 2026 11:38:37 +0000 (13:38 +0200)
This ensures that 'switch' statements work correctly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libxl/xen_common.c
src/qemu/qemu_driver.c

index 17c4a57cd8e19b88abf34e1edf8fcb49107394eb..ab5138acbcbc354ecc092e10eb64056bf08a6e3b 100644 (file)
@@ -14168,21 +14168,23 @@ static int
 virDomainEventActionParseXML(xmlXPathContextPtr ctxt,
                              const char *name,
                              const char *xpath,
-                             int *val,
-                             int defaultVal,
+                             unsigned int *val,
+                             unsigned int defaultVal,
                              virEventActionFromStringFunc convFunc)
 {
     g_autofree char *tmp = virXPathString(xpath, ctxt);
+    int tmpval;
 
     if (tmp == NULL) {
         *val = defaultVal;
     } else {
-        *val = convFunc(tmp);
-        if (*val < 0) {
+        tmpval = convFunc(tmp);
+        if (tmpval < 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown %1$s action: %2$s"), name, tmp);
             return -1;
         }
+        *val = tmpval;
     }
     return 0;
 }
index 0c6c79c41378da5f0d2b017e74867947a5f3168d..91f57de0f13b17a295b75729d474af9644ec6cd6 100644 (file)
@@ -3250,12 +3250,11 @@ struct _virDomainDef {
     virDomainResourceDef *resource;
     virDomainIdMapDef idmap;
 
-    /* These 3 are based on virDomainLifecycleAction enum flags */
-    int onReboot;
-    int onPoweroff;
-    int onCrash;
+    virDomainLifecycleAction onReboot;
+    virDomainLifecycleAction onPoweroff;
+    virDomainLifecycleAction onCrash;
 
-    int onLockFailure; /* enum virDomainLockFailureAction */
+    virDomainLockFailureAction onLockFailure;
 
     virDomainPowerManagement pm;
 
index e6a372e07873ab7c0ae7847c2c4404b201fa0c5f..4b2e47006acded8205fbfb562de9d8c937c8d3a2 100644 (file)
@@ -336,33 +336,37 @@ xenParseEventsActions(virConf *conf, virDomainDef *def)
     g_autofree char *on_poweroff = NULL;
     g_autofree char *on_reboot = NULL;
     g_autofree char *on_crash = NULL;
+    int tmp;
 
     if (xenConfigGetString(conf, "on_poweroff", &on_poweroff, "destroy") < 0)
         return -1;
 
-    if ((def->onPoweroff = virDomainLifecycleActionTypeFromString(on_poweroff)) < 0) {
+    if ((tmp = virDomainLifecycleActionTypeFromString(on_poweroff)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected value %1$s for on_poweroff"), on_poweroff);
         return -1;
     }
+    def->onPoweroff =  tmp;
 
     if (xenConfigGetString(conf, "on_reboot", &on_reboot, "restart") < 0)
         return -1;
 
-    if ((def->onReboot = virDomainLifecycleActionTypeFromString(on_reboot)) < 0) {
+    if ((tmp = virDomainLifecycleActionTypeFromString(on_reboot)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected value %1$s for on_reboot"), on_reboot);
         return -1;
     }
+    def->onReboot = tmp;
 
     if (xenConfigGetString(conf, "on_crash", &on_crash, "restart") < 0)
         return -1;
 
-    if ((def->onCrash = virDomainLifecycleActionTypeFromString(on_crash)) < 0) {
+    if ((tmp = virDomainLifecycleActionTypeFromString(on_crash)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected value %1$s for on_crash"), on_crash);
         return -1;
     }
+    def->onCrash = tmp;
 
     return 0;
 }
index 663e6c33cfefabf575f487c4c968c5d78dd735f4..2fbd7bc3eea6b974e4e728969a5b18c3c0b3e4bb 100644 (file)
@@ -3680,6 +3680,8 @@ processGuestPanicEvent(virQEMUDriver *driver,
         /* the VM is kept around for debugging */
         break;
 
+    case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME:
+    case VIR_DOMAIN_LIFECYCLE_ACTION_LAST:
     default:
         break;
     }