]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch_conf: Move error reporting into chExtractVersionInfo()
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 4 Jun 2021 12:18:50 +0000 (14:18 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 4 Jun 2021 14:39:00 +0000 (16:39 +0200)
If chExtractVersionInfo() fails, in some cases it reports error
and in some it doesn't. Fix those places and drop reporting error
from chExtractVersion() which would just overwrite more specific
error.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/ch/ch_conf.c

index 2dd104b8a81dc656ec2e5cd144aae8cd0225869c..d900ebc7dd977ac6ab5810aa65815ebb92776ef2 100644 (file)
@@ -213,11 +213,17 @@ chExtractVersionInfo(int *retversion)
     tmp = help;
 
     /* expected format: cloud-hypervisor v<major>.<minor>.<micro> */
-    if ((tmp = STRSKIP(tmp, "cloud-hypervisor v")) == NULL)
+    if ((tmp = STRSKIP(tmp, "cloud-hypervisor v")) == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unexpected output of cloud-hypervisor binary"));
         goto cleanup;
+    }
 
-    if (virParseVersionString(tmp, &version, true) < 0)
+    if (virParseVersionString(tmp, &version, true) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse cloud-hypervisor version: %s"), tmp);
         goto cleanup;
+    }
 
     if (version < MIN_VERSION) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -241,11 +247,8 @@ int chExtractVersion(virCHDriver *driver)
     if (driver->version > 0)
         return 0;
 
-    if (chExtractVersionInfo(&driver->version) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Could not extract Cloud-Hypervisor version"));
+    if (chExtractVersionInfo(&driver->version) < 0)
         return -1;
-    }
 
     return 0;
 }