summaryrefslogtreecommitdiffstats
path: root/vmchooser/runImage.cxx
blob: 477bfd3106263481a9a2e9c5dff78e6741567745 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <fltk/Widget.h>

#include "inc/DataEntry.h"
#include "inc/SWindow.h"
#include <sys/wait.h>
#include <iostream>
#include <string>
#include <boost/regex.hpp>

/** *************************************************************
 * void runImage runs a (virtual machine) image using fork()
 ***************************************************************/
void runImage(fltk::Widget*, void* p)
{
  /* printf("runImage called\n"); */
  if ( p == NULL ) {
    return;
  }
  
  DataEntry& dat = *((DataEntry*) p);
  
  pid_t pid;
  int status;
  pid = fork();

  switch( pid )  {
    case -1:
      cout << "Something went wrong while forking!" << endl;
      return;
      break;
    case 0:
      runImage(dat);
      break;
    default:
      exit(0);
      if( waitpid( pid, &status, 0 ) == -1 ) {
        cerr << "No child with this pid (" << pid << ")" << endl;
        return;
      }
      else {
        exit(0);
      }
      break;
  }
}

/**
 * Helper-function for runImage(Widget, void) 
 * - runs the chosen virtualizer image
 **/
string runImage(DataEntry& dat)
{
  if (dat.imgtype == VMWARE) {
  	char* arg[] = { strcat("/var/lib/vmware/",dat.imgname.c_str()),
		(char*) dat.os.c_str(),
		(char*)dat.network.c_str(), '\0' };
	// run-vmware.sh imagename os (Window-Title) network
	execvp("/var/X11R6/bin/run-vmware.sh", arg );
  }
  if(! dat.command.empty() ) {
    execvp((char*) dat.command.c_str(), NULL);
  }
  return string();
}