[virt-tools-list] [virt-viewer][PATCH 1/7 v3] virt-viewer: Add a GError arg to extract_connect_info()

Fabiano Fidêncio fidencio at redhat.com
Thu Mar 26 22:26:54 UTC 2015


This is part of a small re-factoring that will have all connection
errors, when we won't be able to connect regardless of what changes on
the remote host, being treated by virt_viewer_app_initial_connect(),
avoiding weird behaviors as we have nowadays (like more than one error
dialog being shown or having the virt-viewer waiting forever for a guest
that will never show up).

Related: rhbz#1085216
---
 src/virt-viewer.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index 994ee28..1c9f59d 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -387,7 +387,8 @@ virt_viewer_is_reachable(const gchar *host,
 
 static gboolean
 virt_viewer_extract_connect_info(VirtViewer *self,
-                                 virDomainPtr dom)
+                                 virDomainPtr dom,
+                                 GError **error)
 {
     char *type = NULL;
     char *xpath = NULL;
@@ -405,12 +406,18 @@ virt_viewer_extract_connect_info(VirtViewer *self,
     gint port = 0;
     gchar *uri = NULL;
     gboolean direct = virt_viewer_app_get_direct(app);
+    GError *err = NULL;
 
     virt_viewer_app_free_connect_info(app);
 
     if ((type = virt_viewer_extract_xpath_string(xmldesc, "string(/domain/devices/graphics/@type)")) == NULL) {
+        g_set_error(&err,
+                    VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
+                    _("Cannot determine the graphic type for the guest %s"), priv->domkey);
+
         virt_viewer_app_simple_message_dialog(app, _("Cannot determine the graphic type for the guest %s"),
                                               priv->domkey);
+
         goto cleanup;
     }
 
@@ -446,8 +453,13 @@ virt_viewer_extract_connect_info(VirtViewer *self,
 
     uri = virConnectGetURI(priv->conn);
     if (virt_viewer_util_extract_host(uri, NULL, &host, &transport, &user, &port) < 0) {
+        g_set_error(&err,
+                    VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
+                    _("Cannot determine the host for the guest %s"), priv->domkey);
+
         virt_viewer_app_simple_message_dialog(app, _("Cannot determine the host for the guest %s"),
                                               priv->domkey);
+
         goto cleanup;
     }
 
@@ -472,10 +484,16 @@ virt_viewer_extract_connect_info(VirtViewer *self,
     }
 
     if (!virt_viewer_is_reachable(ghost, transport, host, direct)) {
+        g_set_error(&err,
+                    VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
+                    _("Guest '%s' is not reachable"), priv->domkey);
+
         g_debug("graphics listen '%s' is not reachable from this machine",
                 ghost ? ghost : "");
+
         virt_viewer_app_simple_message_dialog(app, _("Guest '%s' is not reachable"),
                                               priv->domkey);
+
         goto cleanup;
     }
 
@@ -484,6 +502,9 @@ virt_viewer_extract_connect_info(VirtViewer *self,
     retval = TRUE;
 
  cleanup:
+    if (err)
+        g_propagate_error(error, err);
+
     g_free(gport);
     g_free(gtlsport);
     g_free(ghost);
@@ -515,7 +536,7 @@ virt_viewer_update_display(VirtViewer *self, virDomainPtr dom)
     g_object_set(app, "guest-name", virDomainGetName(dom), NULL);
 
     if (!virt_viewer_app_has_session(app)) {
-        if (!virt_viewer_extract_connect_info(self, dom))
+        if (!virt_viewer_extract_connect_info(self, dom, NULL))
             return FALSE;
     }
 
-- 
2.3.3




More information about the virt-tools-list mailing list