[virt-tools-list] [PATCH virt-viewer 6/9] Simplify virt_viewer_initial_connect()

Marc-André Lureau marcandre.lureau at gmail.com
Thu Nov 13 17:20:42 UTC 2014


Some refactoring to make the code easier to read.
- do not overwrite err if ->initial_connect() sets it
- remove need for waitvm if the display server isn't yet started (note:
  this function might be untested, I am not sure relying on libvirt events
  is enough)
---
 src/virt-viewer.c | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index 6810908..c1d2765 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -641,7 +641,7 @@ virt_viewer_initial_connect(VirtViewerApp *app, GError **error)
     if (!priv->conn &&
         virt_viewer_connect(app) < 0) {
         virt_viewer_app_show_status(app, _("Waiting for libvirt to start"));
-        goto done;
+        goto wait;
     }
 
     virt_viewer_app_show_status(app, _("Finding guest domain"));
@@ -649,9 +649,7 @@ virt_viewer_initial_connect(VirtViewerApp *app, GError **error)
     if (!dom) {
         if (priv->waitvm) {
             virt_viewer_app_show_status(app, _("Waiting for guest domain to be created"));
-            virt_viewer_app_trace(app, "Guest %s does not yet exist, waiting for it to be created",
-                                  priv->domkey);
-            goto done;
+            goto wait;
         } else {
             dom = choose_vm(&priv->domkey, priv->conn, &err);
             if (dom == NULL && err != NULL) {
@@ -675,27 +673,22 @@ virt_viewer_initial_connect(VirtViewerApp *app, GError **error)
 
     if (info.state == VIR_DOMAIN_SHUTOFF) {
         virt_viewer_app_show_status(app, _("Waiting for guest domain to start"));
-    } else {
-        ret = virt_viewer_update_display(self, dom);
-        if (ret)
-            ret = VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->initial_connect(app, &err);
-        if (!ret) {
-            if (priv->waitvm) {
-                virt_viewer_app_show_status(app, _("Waiting for guest domain to start server"));
-                virt_viewer_app_trace(app, "Guest %s has not activated its display yet, waiting for it to start",
-                                      priv->domkey);
-            } else {
-                g_set_error_literal(&err, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
-                                    _("Failed to activate viewer"));
-                g_debug("%s", err->message);
-                goto cleanup;
-            }
-        }
+        goto wait;
     }
 
- done:
+    if (!virt_viewer_update_display(self, dom))
+        goto wait;
+
+    ret = VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->initial_connect(app, &err);
+    if (ret || err)
+        goto cleanup;
+
+wait:
+    virt_viewer_app_trace(app, "Guest %s has not activated its display yet, waiting "
+                          "for it to start", priv->domkey);
     ret = TRUE;
- cleanup:
+
+cleanup:
     if (err != NULL)
         g_propagate_error(error, err);
     if (dom)
-- 
1.9.3




More information about the virt-tools-list mailing list