summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBastian Wissler2008-04-18 14:17:00 +0200
committerBastian Wissler2008-04-18 14:17:00 +0200
commit74344c12830b6c0281bfee7191d77d0c70c7eec5 (patch)
treeeac87034c441a0162ce4d9a48b1a43e81600185d
parentmissing CXX-file (diff)
downloadvmchooser-74344c12830b6c0281bfee7191d77d0c70c7eec5.tar.gz
vmchooser-74344c12830b6c0281bfee7191d77d0c70c7eec5.tar.xz
vmchooser-74344c12830b6c0281bfee7191d77d0c70c7eec5.zip
minor changes which enables fork()ing and execvp()ing
git-svn-id: http://svn.openslx.org/svn/openslx/openslx-src-tools/trunk/os-plugins/plugins/vmchooser@1749 95ad53e4-c205-0410-b2fa-d234c58c8868
-rw-r--r--vmchooser/inc/functions.h2
-rw-r--r--vmchooser/runImage.cxx41
2 files changed, 18 insertions, 25 deletions
diff --git a/vmchooser/inc/functions.h b/vmchooser/inc/functions.h
index c95170a..c8dcc86 100644
--- a/vmchooser/inc/functions.h
+++ b/vmchooser/inc/functions.h
@@ -11,7 +11,7 @@ DataEntry** readXmlDir(char* path); /* Attention: returns malloced array */
DataEntry** readLinSess(char* path);
void runImage(fltk::Widget* , void* p); /* This is thought as a callback-function for the Select-Browser */
-string buildCommand(DataEntry&); /* building command for different Virtualizer */
+string runImage(DataEntry&); /* building command for different Virtualizer */
glob_t* globber(char* path, char* filetype); /* Globs for a specific filetype */
diff --git a/vmchooser/runImage.cxx b/vmchooser/runImage.cxx
index 52b1dc4..477bfd3 100644
--- a/vmchooser/runImage.cxx
+++ b/vmchooser/runImage.cxx
@@ -4,10 +4,11 @@
#include "inc/SWindow.h"
#include <sys/wait.h>
#include <iostream>
+#include <string>
+#include <boost/regex.hpp>
/** *************************************************************
- * void runImage runs a Image - building the commandline
- * and executes it using system()
+ * void runImage runs a (virtual machine) image using fork()
***************************************************************/
void runImage(fltk::Widget*, void* p)
{
@@ -18,29 +19,23 @@ void runImage(fltk::Widget*, void* p)
DataEntry& dat = *((DataEntry*) p);
- string comm = buildCommand(dat);
-
- /* No command here - faulty session ?!? */
- if( comm.empty() ) {
- return;
- }
-
pid_t pid;
int status;
pid = fork();
-
+
switch( pid ) {
case -1:
cout << "Something went wrong while forking!" << endl;
return;
break;
- case 0:
- system( comm.c_str() );
- exit(0);
+ 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);
@@ -50,22 +45,20 @@ void runImage(fltk::Widget*, void* p)
}
/**
- * Helper-function for runImage(Widget, void) - builds the command
+ * Helper-function for runImage(Widget, void)
+ * - runs the chosen virtualizer image
**/
-string buildCommand(DataEntry& dat)
+string runImage(DataEntry& dat)
{
if (dat.imgtype == VMWARE) {
- // run-vmware.sh imagename os(Window-Title) network
- return string("/var/X11R6/bin/run-vmware.sh \"/var/lib/vmware/")
- .append(dat.imgname)
- .append("\" \"")
- .append(dat.os)
- .append("\" \"")
- .append(dat.network)
- .append("\"");
+ 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() ) {
- return dat.command;
+ execvp((char*) dat.command.c_str(), NULL);
}
return string();
}