[libvirt] [PATCH libvirt-glib 3/5] Ensure internal copy of URI is not NULL

Daniel P. Berrange berrange at redhat.com
Wed Nov 30 16:52:05 UTC 2011


From: "Daniel P. Berrange" <berrange at redhat.com>

It is permissible to pass in NULL for a URI to libvirt, which
causes it to probe for a supported driver. In such a case we
should populate priv->uri with the resulting probed URI after
opening the connection

* libvirt-gobject/libvirt-gobject-connection.c: Populate URI
  after opening connection, if NULL
---
 libvirt-gobject/libvirt-gobject-connection.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 59b828d..a1a6f5d 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -415,6 +415,18 @@ gboolean gvir_connection_open(GVirConnection *conn,
         return FALSE;
     }
 
+    if (!priv->uri &&
+        !(priv->uri = virConnectGetURI(priv->conn))) {
+        if (err)
+            *err = gvir_error_new(GVIR_CONNECTION_ERROR,
+                                  0,
+                                  "%s", "Unable to get connection URI");
+        virConnectClose(priv->conn);
+        priv->conn = NULL;
+        g_mutex_unlock(priv->lock);
+        return FALSE;
+    }
+
     if (virConnectDomainEventRegister(priv->conn, domain_event_cb, conn, NULL) != -1)
         priv->domain_event = TRUE;
     else
-- 
1.7.6.4




More information about the libvir-list mailing list