[PATCH libvirt-glib v2 2/8] Ensure internal copy of URI is not NULL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

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 |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 786a026..ffdc62f 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -420,6 +420,22 @@ gboolean gvir_connection_open(GVirConnection *conn,
         return FALSE;
     }
 
+    if (!priv->uri) {
+        char *uri = virConnectGetURI(priv->conn);
+        if (!uri) {
+            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;
+        }
+        priv->uri = g_strdup(uri);
+        free(uri);
+    }
+
     if (virConnectDomainEventRegister(priv->conn, domain_event_cb, conn, NULL) != -1)
         priv->domain_event = TRUE;
     else
-- 
1.7.6.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]