Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some cppcheck cleaning #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 23 additions & 29 deletions CernVMwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ VM::VM(){
current_period=0;
suspended=false;
last_poll_point=0;
poll_err_number=0;

//boinc_resolve_filename_s("cernvm.vmdk.gz",disk_path);
// fprintf(stderr,"%s\n",disk_path.c_str());
Expand All @@ -294,7 +295,6 @@ void VM::create() {
string arg_list;

//createvm
arg_list="";
arg_list="createvm --name "+virtual_machine_name+ \
" --ostype Linux26 --register";
if(!vbm_popen(arg_list)){
Expand All @@ -310,7 +310,6 @@ void VM::create() {
}

//modifyvm
arg_list="";
arg_list="modifyvm "+virtual_machine_name+ \
" --memory 256 --acpi on --ioapic on \
--boot1 disk --boot2 none --boot3 none --boot4 none \
Expand All @@ -329,7 +328,6 @@ void VM::create() {


//storagectl
arg_list="";
arg_list="storagectl "+virtual_machine_name+ \
" --name \"IDE Controller\" --add ide --controller PIIX4";
vbm_popen(arg_list);
Expand All @@ -341,7 +339,6 @@ void VM::create() {
// vbm_popen(arg_list);

//storageattach
arg_list="";
arg_list="storageattach "+virtual_machine_name+ \
" --storagectl \"IDE Controller\" \
--port 0 --device 0 --type hdd --medium " \
Expand Down Expand Up @@ -443,20 +440,17 @@ void VM::start(bool vrde=false, bool headless=false) {
// Enable or disable VRDP for the VM: (by default is disabled)
if (vrde)
{
arg_list = "";
arg_list = " controlvm " + virtual_machine_name + " vrde on";
}
else
{
arg_list = "";
arg_list = " controlvm " + virtual_machine_name + " vrde off";
}
vbm_popen(arg_list);

// If not running in Headless mode, don't allow the user to save, shutdown, power off or restore the VM
if (!headless)
{
arg_list = "";
// Don't allow the user to save, shutdown, power off or restore the VM
arg_list = " setextradata " + virtual_machine_name + " GUI/RestrictedCloseActions SaveState,Shutdown,PowerOff,Restore";
vbm_popen(arg_list);
Expand All @@ -469,16 +463,14 @@ void VM::start(bool vrde=false, bool headless=false) {

void VM::kill() {
boinc_begin_critical_section();
string arg_list="";
arg_list="controlvm "+virtual_machine_name+" poweroff";
string arg_list="controlvm "+virtual_machine_name+" poweroff";
vbm_popen(arg_list);
boinc_end_critical_section();
}

void VM::pause() {
boinc_begin_critical_section();
string arg_list="";
arg_list="controlvm "+virtual_machine_name+" pause";
string arg_list="controlvm "+virtual_machine_name+" pause";
if(vbm_popen(arg_list)) {
suspended = true;
time_t current_time = time(NULL);
Expand All @@ -490,8 +482,7 @@ void VM::pause() {

void VM::resume() {
boinc_begin_critical_section();
string arg_list="";
arg_list="controlvm "+virtual_machine_name+" resume";
string arg_list="controlvm "+virtual_machine_name+" resume";
if(vbm_popen(arg_list)) {
suspended = false;
last_poll_point=time(NULL);
Expand All @@ -515,8 +506,7 @@ void VM::Check(){
void VM::savestate()
{
boinc_begin_critical_section();
string arg_list = "";
arg_list = "controlvm " + virtual_machine_name + " savestate";
string arg_list = "controlvm " + virtual_machine_name + " savestate";
if (!vbm_popen(arg_list))
{
if (debug >= 1) fprintf(stderr,"ERROR: The VM could not be saved.\n");
Expand All @@ -527,26 +517,23 @@ void VM::savestate()

void VM::remove(){
boinc_begin_critical_section();
string arg_list="",vminfo, vboxfolder, vboxXML, vboxXMLNew, vmfolder, vmdisk;
string arg_list,vminfo, vboxfolder, vboxXML, vboxXMLNew, vmfolder, vmdisk;
char * env;
bool vmRegistered = false;


arg_list = "";
arg_list = " discardstate " + virtual_machine_name;
if (vbm_popen(arg_list)) if (debug >= 3) fprintf(stderr,"NOTICE: VM state discarded!\n");
else if (debug >= 2) fprintf(stderr,"WARNING: it was not possible to discard the state of the VM.\n");

// Unregistervm command with --delete option. VBox 4.1 should work well
arg_list = "";
arg_list = " unregistervm " + virtual_machine_name + " --delete";
if (vbm_popen(arg_list)) if (debug >= 3) fprintf(stderr, "NOTICE: VM unregistered and deleted via VBoxManage.\n");
else if (debug >= 2) fprintf(stderr, "WARNING: The VM could not be removed via VBoxManage.\n");

// We test if we can remove the hard disk controller. If the command works, the cernvm.vmdk virtual disk will be also
// removed automatically

arg_list = "";
arg_list = " storagectl " + virtual_machine_name + " --name \"IDE Controller\" --remove";
if (vbm_popen(arg_list)) if (debug >= 3) fprintf(stderr, "NOTICE: Hard disk removed!\n");
else if (debug >= 2) fprintf(stderr,"WARNING: it was not possible to remove the IDE controller.\n");
Expand Down Expand Up @@ -641,18 +628,26 @@ void VM::remove(){
{
vmfolder = "RMDIR \"" + vmfolder + "\" /s /q";
if (system(vmfolder.c_str()) == 0)
{
if (debug >= 3) fprintf(stderr,"NOTICE: VM folder deleted!\n");
}
else
{
if (debug >= 3) fprintf(stderr,"NOTICE: System was clean, nothing to delete.\n");
}
}
else
{
if (debug >= 3) fprintf(stderr,"NOTICE: VM was not registered, deleting old VM folders...\n");
vmfolder = "RMDIR \"" + vboxfolder + virtual_machine_name + "\" /s /q";
if ( system(vmfolder.c_str()) == 0 )
{
if (debug >= 3) fprintf(stderr,"NOTICE: VM folder deleted!\n");
}
else
{
if (debug >= 3) fprintf(stderr,"NOTICE: System was clean, nothing to delete.\n");
}
}

#else // GNU/Linux and Mac OS X
Expand All @@ -661,7 +656,9 @@ void VM::remove(){
{
vmfolder = "rm -rf \"" + vmfolder + "\"";
if ( system(vmfolder.c_str()) == 0 )
{
if (debug >= 3) fprintf(stderr,"NOTICE: VM folder deleted!\n");
}
else
{
if (debug >= 3) fprintf(stderr,"NOTICE: System was clean, nothing to delete.\n");
Expand All @@ -672,18 +669,21 @@ void VM::remove(){
if (debug >= 3) fprintf(stderr,"NOTICE: VM was not registered, deleting old VM folders...\n");
vmfolder = "rm -rf \"" + string(env) + "/VirtualBox VMs/" + virtual_machine_name + "\" ";
if ( system(vmfolder.c_str()) == 0 )
{
if (debug >= 3) fprintf(stderr,"NOTICE: VM folder deleted!\n");
}
else
{
if (debug >= 3) fprintf(stderr,"NOTICE: System was clean, nothing to delete.\n");
}
}
#endif
boinc_end_critical_section();
}

void VM::release(){
boinc_begin_critical_section();
string arg_list="";
arg_list="closemedium disk "+disk_path;
string arg_list="closemedium disk "+disk_path;
if(!vbm_popen(arg_list))
{
if (debug >= 1) fprintf(stderr,"ERROR: It was impossible to release the virtual hard disk\n");
Expand All @@ -700,7 +700,6 @@ void VM::poll() {
time_t current_time;


arg_list="";
arg_list="showvminfo "+virtual_machine_name+" --machinereadable" ;
if (!vbm_popen(arg_list,buffer,sizeof(buffer))){
// Increase the number of errors
Expand Down Expand Up @@ -739,8 +738,8 @@ void VM::poll() {
if (debug >= 4) fprintf(stderr,"INFO: VM poll is running\n");
}
boinc_end_critical_section();
return;
if (debug >= 3) fprintf(stderr,"NOTICE: VM is running!\n"); //testing
return;
}

if(status.find("VMState=\"paused\"") != string::npos){
Expand Down Expand Up @@ -883,9 +882,6 @@ int main(int argc, char** argv) {
// The VM
VM vm;

// Init the errors number
vm.poll_err_number = 0;

// Registering time for progress accounting
time_t init_secs = time (NULL);
//fprintf(stderr,"INFO: %ld seconds since January 1, 1970\n", init_secs);
Expand Down Expand Up @@ -1092,11 +1088,9 @@ int main(int argc, char** argv) {
fprintf(stderr,"VMName exists\n");

bool VMexist=false;
string arg_list;
if (debug >= 3) fprintf(stderr,"NOTICE: Virtual machine name %s\n",vm.virtual_machine_name.c_str());

arg_list="";
arg_list=" list vms";
string arg_list=" list vms";
if (!vbm_popen(arg_list,buffer,sizeof(buffer))){
if (debug >= 1) fprintf(stderr, "ERROR: CernVMManager list failed!\n");
boinc_finish(1);
Expand Down
2 changes: 1 addition & 1 deletion sample_work_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int make_job(char* inputfile) {
wu.max_total_results = REPLICATION_FACTOR*8;
wu.max_success_results = REPLICATION_FACTOR*4;
// Specify the input file. If thre is no argument, use the last hard-coded version
if (inputfile != "") infiles[0] = inputfile;
if (strcmp(inputfile, "") != 0) infiles[0] = inputfile;
else infiles[0] = "cernvm.vmdk.gz=cernvm_2.3.3_vmdk.gz";

// Register the job with BOINC
Expand Down