From 9f42c5dc0066e1d46ff2568e40042b8f00db145a Mon Sep 17 00:00:00 2001
From: Rom Walton <rwalton@ssl.berkeley.edu>
Date: Sat, 4 Jul 2015 12:31:23 -0400
Subject: [PATCH] VBOX: Attempt to gracefully fallback to using vboxmanage when
 the COM interface cannot be successfully created.

---
 samples/vboxwrapper/vbox_common.h   |  1 +
 samples/vboxwrapper/vboxwrapper.cpp | 38 ++++++++++++++++++++++-------
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/samples/vboxwrapper/vbox_common.h b/samples/vboxwrapper/vbox_common.h
index 5a07efcb31..05ffdc7c70 100644
--- a/samples/vboxwrapper/vbox_common.h
+++ b/samples/vboxwrapper/vbox_common.h
@@ -244,6 +244,7 @@ public:
 };
 
 class VBOX_VM : public VBOX_BASE {
+public:
     VBOX_VM();
     ~VBOX_VM();
 };
diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp
index 43d52f022b..e08c2c7e20 100644
--- a/samples/vboxwrapper/vboxwrapper.cpp
+++ b/samples/vboxwrapper/vboxwrapper.cpp
@@ -454,19 +454,47 @@ int main(int argc, char** argv) {
         sscanf(vbox_version.c_str(), "%d.%d", &vbox_major, &vbox_minor);
         if ((4 == vbox_major) && (2 == vbox_minor)) {
             pVM = (VBOX_VM*) new vbox42::VBOX_VM();
+            retval = pVM->initialize();
+            if (retval) {
+                delete pVM;
+                pVM = NULL;
+            }
         }
         if ((4 == vbox_major) && (3 == vbox_minor)) {
             pVM = (VBOX_VM*) new vbox43::VBOX_VM();
+            retval = pVM->initialize();
+            if (retval) {
+                delete pVM;
+                pVM = NULL;
+            }
         }
-        if ((5 == vbox_major) && (0 == vbox_minor)) {
+        if ((5 == vbox_major) && (0 >= vbox_minor)) {
             pVM = (VBOX_VM*) new vbox50::VBOX_VM();
+            retval = pVM->initialize();
+            if (retval) {
+                delete pVM;
+                pVM = NULL;
+            }
         }
     }
     if (!pVM) {
         pVM = (VBOX_VM*) new vboxmanage::VBOX_VM();
+        retval = pVM->initialize();
+        if (retval) {
+            vboxlog_msg("Could not detect VM Hypervisor. Rescheduling execution for a later date.");
+            boinc_temporary_exit(86400, "Detection of VM Hypervisor failed.");
+        }
     }
 #else
     pVM = (VBOX_VM*) new vboxmanage::VBOX_VM();
+
+    // Initialize VM Hypervisor
+    //
+    retval = pVM->initialize();
+    if (retval) {
+        vboxlog_msg("Could not detect VM Hypervisor. Rescheduling execution for a later date.");
+        boinc_temporary_exit(86400, "Detection of VM Hypervisor failed.");
+    }
 #endif
 
     // Parse command line parameters
@@ -516,14 +544,6 @@ int main(int argc, char** argv) {
     }
 #endif
 
-    // Initialize VM Hypervisor
-    //
-    retval = pVM->initialize();
-    if (retval) {
-        vboxlog_msg("Could not detect VM Hypervisor. Rescheduling execution for a later date.");
-        boinc_temporary_exit(86400, "Detection of VM Hypervisor failed.");
-    }
-
     // Record what version of VirtualBox was used.
     // 
     if (!pVM->virtualbox_version.empty()) {
-- 
GitLab