From 5a863d3524774c49603295964767e75ea71c934e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Lombra=C3=B1a=20Gonz=C3=A1lez?= Date: Mon, 13 Aug 2012 13:08:34 +0200 Subject: [PATCH] Floppy random name based on time. Close #38 The floppy name is generated using the time since EPOCH as a tag to avoid floppy registration errors. --- cernvm-wrapper.cpp | 2 +- vbox.h | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cernvm-wrapper.cpp b/cernvm-wrapper.cpp index 1c2bdc4..faa1013 100644 --- a/cernvm-wrapper.cpp +++ b/cernvm-wrapper.cpp @@ -238,7 +238,7 @@ int main(int argc, char** argv) else { cerr << "VM exists, starting it..." << endl; } - + time_t elapsed_secs = 0; long int t = 0; double frac_done = 0, dif_secs = 0; diff --git a/vbox.h b/vbox.h index ab359c0..6d69d5e 100644 --- a/vbox.h +++ b/vbox.h @@ -282,7 +282,18 @@ void VM::create() } // Create the controller for the virtual floppy image - FloppyIO floppy("floppy.img"); + unsigned long int slug = time(NULL); + string floppy_name; + std::stringstream out; + out << "floppy_" << slug << ".img"; + floppy_name = out.str(); + // Save the name of the floppy + ofstream myfile; + myfile.open("FloppyName.txt"); + myfile << floppy_name << endl; + myfile.close(); + // Create the Floppy image + FloppyIO floppy(floppy_name.c_str()); arg_list.clear(); arg_list = "storagectl " + virtual_machine_name + \ " --name \"Floppy Controller\" --add floppy"; @@ -292,7 +303,7 @@ void VM::create() arg_list.clear(); arg_list = "storageattach " + virtual_machine_name + \ " --storagectl \"Floppy Controller\" \ - --port 0 --device 0 --medium floppy.img"; + --port 0 --device 0 --medium " + floppy_name.c_str(); if (!vbm_popen(arg_list)) { cerr << "ERROR: Adding the Floppy image failed! Aborting" << endl; @@ -658,7 +669,7 @@ void VM::remove() // Wait to allow to discard the VM state cleanly boinc_sleep(2); - + // Unregistervm command with --delete option. VBox 4.1 should work well arg_list.clear(); arg_list = " unregistervm " + virtual_machine_name + " --delete";