diff --git a/checkin_notes b/checkin_notes index 1dd4d8e6a4..ff0ef9936f 100644 --- a/checkin_notes +++ b/checkin_notes @@ -5950,3 +5950,10 @@ Rom 13 Sept 2011 samples/vboxwrapper/ vbox.cpp + +Rom 13 Sept 2011 + - VBOX: Make is_running() a bit smarter about detecting the running state + of a virtual machine. + + samples/vboxwrapper/ + vbox.cpp diff --git a/samples/vboxwrapper/vbox.cpp b/samples/vboxwrapper/vbox.cpp index 4a8b81e24a..e0e00609ab 100644 --- a/samples/vboxwrapper/vbox.cpp +++ b/samples/vboxwrapper/vbox.cpp @@ -80,6 +80,9 @@ int VBOX_VM::run() { retval = startvm(); if (retval) return retval; + // Give time enough for external processes to begin the VM boot process + boinc_sleep(1.0); + return 0; } @@ -288,12 +291,42 @@ bool VBOX_VM::is_hdd_registered() { bool VBOX_VM::is_running() { string command; string output; + string vmstate; + size_t vmstate_location; + size_t vmstate_length; - command = "list runningvms"; - + command = "showvminfo \"" + vm_name + "\" --machinereadable "; if (vbm_popen(command, output) == 0) { - if (output.find(vm_name) != string::npos) { - return true; + + vmstate_location = output.find("VMState=\""); + if (vmstate_location != string::npos) { + vmstate_location += 9; + vmstate_length = output.find("\"", vmstate_location); + vmstate = output.substr(vmstate_location, vmstate_length); + + // VirtualBox Documentation suggests that that a VM is running when its + // machine state is between MachineState_FirstOnline and MachineState_LastOnline + // which as of this writing is 5 and 17. + // + // VboxManage's source shows more than that though: + // see: http://www.virtualbox.org/browser/trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp + // + // So for now, go with what VboxManage is reporting. + // + if (vmstate == "running") return true; + if (vmstate == "paused") return true; + if (vmstate == "gurumeditation") return true; + if (vmstate == "livesnapshotting") return true; + if (vmstate == "teleporting") return true; + if (vmstate == "starting") return true; + if (vmstate == "stopping") return true; + if (vmstate == "saving") return true; + if (vmstate == "restoring") return true; + if (vmstate == "teleportingpausedvm") return true; + if (vmstate == "teleportingin") return true; + if (vmstate == "restoringsnapshot") return true; + if (vmstate == "deletingsnapshot") return true; + if (vmstate == "deletingsnapshotlive") return true; } } diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index 8895906054..0644823bbd 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -209,8 +209,8 @@ int main(int argc, char** argv) { set_throttles(aid, vm); - bool have_vm_pid = false; int vm_pid; + bool have_vm_pid = false; bool reported_vm_pid = false; while (1) {