[libvirt] [libvirt-glib] Return an error when virConnectGetVersion returns 0

Christophe Fergeau cfergeau at redhat.com
Wed Nov 21 14:26:03 UTC 2012


virConnectGetVersion can return 0 'if the version can't be extracted
by lack of capabilities'. I've also seen it return 0 when libvirtd
1.0 is running but virsh 0.10.2 is used to get the version.
gvir_connection_get_version is documented as returning 0 on error.
However, currently it only sets the corresponding GError when
virConnectGetVersion returns -1. Makes sure the GError is also
set when 0 is returned. The old behaviour was causing a crash
in conn-test as this assumes that the GError will be set when
gvir_connection_get_version returns 0.
---
 libvirt-gobject/libvirt-gobject-connection.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 3157a66..91cc535 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -1108,6 +1108,12 @@ gvir_connection_get_version(GVirConnection *conn,
     if (virConnectGetVersion(priv->conn, &ret) < 0) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, 0,
                                "Unable to get hypervisor version");
+        ret = 0;
+    } else if (ret == 0) {
+        /* From virConnectGetVersion doc: "if the version can't be
+         * extracted by lack of capacities returns 0 and @hvVer is 0" */
+        g_set_error_literal(err, GVIR_CONNECTION_ERROR, 0,
+                            "Unknown hypervisor version");
     }
 
 cleanup:
-- 
1.8.0




More information about the libvir-list mailing list