[gnome-boxes] Fix multiple connections on startup



commit 0d5f162b7a4e16063d9778335cb47e1646dd219d
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Sep 21 15:48:34 2012 +0200

    Fix multiple connections on startup
    
    This is a better fix for bug 683042 (where we connect twice
    when clicking on a box). It fixes the race where we connect twice
    as well as fix the regression where password authentication was
    broken.
    
    We now handle the race by making connect_display() safe to run
    multiple times by:
     * Making update_display() only create a display if needed.
       This is safe as we always clear the display property before
       reconnecting.
     * The Display.connect_it() method was changed to only connect
       once.
    
    Additionally we make reconnect_display() only reconnect if there
    is already a display. This means that if we hit reconnect_display() before
    the initial connect_display() has started connecting we don't connect.
    This ensures connect_display() does the actual connection, so that it
    can properly report any errors.

 src/libvirt-machine.vala |   16 ++++------------
 1 files changed, 4 insertions(+), 12 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 23d03fc..20edd3e 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -14,27 +14,17 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
         set { source.set_boolean ("source", "save-on-quit", value); }
     }
 
-    private bool _connect_display;
-    private bool _reconnect_display;
     public override void disconnect_display () {
         stay_on_display = false;
 
         base.disconnect_display ();
-
-        _connect_display = false;
-        _reconnect_display = true;
     }
 
     public override async void connect_display () throws GLib.Error {
-        if (_connect_display)
-            return;
-
-        _connect_display = true;
         yield start ();
 
         update_display ();
         display.connect_it ();
-        _reconnect_display = true;
     }
 
     struct MachineStat {
@@ -71,7 +61,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     }
 
     private void reconnect_display () {
-        if (!_reconnect_display)
+        // If we haven't connected yet, don't reconnect
+        if (display == null)
             return;
 
         disconnect_display ();
@@ -334,7 +325,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     private void update_display () throws GLib.Error {
         update_domain_config ();
 
-        display = create_display ();
+        if (display == null)
+            display = create_display ();
     }
 
     private Display? create_display () throws Boxes.Error {



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