diff --git a/samples/vboxwrapper/vbox.cpp b/samples/vboxwrapper/vbox.cpp index 4650ccea3f..22cec5e9ad 100644 --- a/samples/vboxwrapper/vbox.cpp +++ b/samples/vboxwrapper/vbox.cpp @@ -1004,7 +1004,8 @@ int VBOX_VM::run(double elapsed_time) { // Check to see if the VM is already in a running state, if so, poweroff. poll(false); if (online) { - poweroff(); + retval = poweroff(); + if (retval) return ERR_NOT_EXITED; } // If our last checkpoint time is greater than 0, restore from the previously diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index b1d5742ee1..5687352e35 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -656,10 +656,6 @@ int main(int argc, char** argv) { char* temp_reason = (char*)""; int temp_delay = 300; - // Attempt to cleanup the VM - vm.cleanup(); - write_checkpoint(elapsed_time, vm); - fprintf( stderr, "%s VM failed to start.\n", @@ -704,23 +700,30 @@ int main(int argc, char** argv) { ); unrecoverable_error = false; temp_reason = (char*)"VM Hypervisor was unable to allocate enough memory to start VM."; + } else if (ERR_NOT_EXITED == retval) { + fprintf( + stderr, + "%s NOTE: VM was already running. BOINC will be notified that it needs to clean up the environment.\n" + " This might be a temporary problem and so this job will be rescheduled for another time.\n", + vboxwrapper_msg_prefix(buf, sizeof(buf)) + ); + unrecoverable_error = false; + temp_reason = (char*)"VM environment needed to be cleaned up."; } else { - vm.poll(); + vm.dumphypervisorlogs(); + } - // Check to see if the VM is already running. If so, notify BOINC about the process ID so it can + if (unrecoverable_error) { + // Attempt to cleanup the VM and exit. + vm.cleanup(); + write_checkpoint(elapsed_time, vm); + boinc_finish(retval); + } else { + // if the VM is already running notify BOINC about the process ID so it can // clean up the environment. We should be safe to run after that. // - if (vm.online) { - fprintf( - stderr, - "%s NOTE: VM was already running. BOINC will be notified that it needs to clean up the environment.\n" - " This might be a temporary problem and so this job will be rescheduled for another time.\n", - vboxwrapper_msg_prefix(buf, sizeof(buf)) - ); - unrecoverable_error = false; - temp_reason = (char*)"VM environment needed to be cleaned up."; - - vm.get_vm_process_id(vm_pid); + vm.get_vm_process_id(vm_pid); + if (vm_pid) { retval = boinc_report_app_status_aux( elapsed_time, checkpoint_cpu_time, @@ -729,16 +732,7 @@ int main(int argc, char** argv) { bytes_sent, bytes_received ); - } else { - - vm.dumphypervisorlogs(); - } - } - - if (unrecoverable_error) { - boinc_finish(retval); - } else { boinc_temporary_exit(temp_delay, temp_reason); } }