summaryrefslogtreecommitdiffstats
path: root/vmchooser/runImage.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'vmchooser/runImage.cxx')
-rw-r--r--vmchooser/runImage.cxx73
1 files changed, 56 insertions, 17 deletions
diff --git a/vmchooser/runImage.cxx b/vmchooser/runImage.cxx
index 76b183b..52b1dc4 100644
--- a/vmchooser/runImage.cxx
+++ b/vmchooser/runImage.cxx
@@ -2,31 +2,70 @@
#include "inc/DataEntry.h"
#include "inc/SWindow.h"
+#include <sys/wait.h>
+#include <iostream>
-
+/** *************************************************************
+ * void runImage runs a Image - building the commandline
+ * and executes it using system()
+ ***************************************************************/
void runImage(fltk::Widget*, void* p)
{
- if ( p == NULL )
- {
- return;
- }
+ /* printf("runImage called\n"); */
+ if ( p == NULL ) {
+ return;
+ }
+
DataEntry& dat = *((DataEntry*) p);
- SWindow& win = *SWindow::getInstance();
+
+ string comm = buildCommand(dat);
- if (! dat.command.empty())
- {
- system(dat.command.c_str());
- win.hide();
- }
- exit(0);
-}
+ /* 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);
+ break;
+ default:
+ if( waitpid( pid, &status, 0 ) == -1 ) {
+ cerr << "No child with this pid (" << pid << ")" << endl;
+ }
+ else {
+ exit(0);
+ }
+ break;
+ }
+}
+/**
+ * Helper-function for runImage(Widget, void) - builds the command
+ **/
string buildCommand(DataEntry& dat)
{
- if (dat.imgtype == VMWARE)
- {
- return string("vmrun ").append(dat.imgname);
- }
+ 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("\"");
+ }
+ if(! dat.command.empty() ) {
+ return dat.command;
+ }
return string();
}