fixed scenario loading
[strongswan.git] / src / dumm / guest.c
index abed806..bbb59f4 100644 (file)
@@ -24,6 +24,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <dirent.h>
+#include <termios.h>
 
 #include <debug.h>
 #include <utils/linked_list.h>
@@ -43,6 +44,7 @@
 #define KERNEL_FILE "linux"
 #define LOG_FILE "boot.log"
 #define NOTIFY_FILE "notify"
+#define PTYS 0
 
 typedef struct private_guest_t private_guest_t;
 
@@ -168,6 +170,18 @@ static char* write_arg(char **pos, size_t *left, char *format, ...)
 }
 
 /**
+ * Implementation of get_t.close_console.
+ */
+static char* get_console(private_guest_t *this, int console)
+{
+       if (this->state == GUEST_RUNNING)
+       {
+               return this->mconsole->get_console_pts(this->mconsole, console);
+       }
+       return NULL;
+}
+
+/**
  * Implementation of guest_t.stop.
  */
 static void stop(private_guest_t *this)
@@ -212,15 +226,8 @@ static bool start(private_guest_t *this)
        args[i++] = write_arg(&pos, &left, "umid=%s", this->name);
        args[i++] = write_arg(&pos, &left, "mem=%dM", this->mem);
        args[i++] = write_arg(&pos, &left, "mconsole=notify:%s", notify);
-       /*args[i++] = write_arg(&pos, &left, "con=pts");*/
-       args[i++] = write_arg(&pos, &left, "con0=null,fd:%d", this->bootlog);
-       //args[i++] = write_arg(&pos, &left, "con0=fd:0,fd:1");
-       //args[i++] = write_arg(&pos, &left, "con1=null,null");
-       args[i++] = write_arg(&pos, &left, "con2=null,null");
-       args[i++] = write_arg(&pos, &left, "con3=null,null");
-       args[i++] = write_arg(&pos, &left, "con4=null,null");
-       args[i++] = write_arg(&pos, &left, "con5=null,null");
-       args[i++] = write_arg(&pos, &left, "con6=null,null");
+       args[i++] = write_arg(&pos, &left, "con=pts");
+       args[i++] = write_arg(&pos, &left, "con0=none,fd:%d", this->bootlog);
        args[i++] = NULL;
          
        this->pid = fork();
@@ -247,21 +254,22 @@ static bool start(private_guest_t *this)
                stop(this);
                return FALSE;
        }
+       
        this->state = GUEST_RUNNING;
        return TRUE;
 }      
        
 /**
- * Implementation of guest_t.set_scenario.
+ * Implementation of guest_t.load_template.
  */
-static bool set_scenario(private_guest_t *this, char *path)
+static bool load_template(private_guest_t *this, char *path)
 {
        char dir[PATH_MAX];
        size_t len;
        
        if (path == NULL)
        {
-               return this->cowfs->set_scenario(this->cowfs, NULL);    
+               return this->cowfs->set_overlay(this->cowfs, NULL);     
        }
        
        len = snprintf(dir, sizeof(dir), "%s/%s", path, this->name);
@@ -273,11 +281,11 @@ static bool set_scenario(private_guest_t *this, char *path)
        {
                if (mkdir(dir, PERME) != 0)
                {
-                       DBG1("creating scenario overlay for guest '%s' failed: %m", this->name);
+                       DBG1("creating overlay for guest '%s' failed: %m", this->name);
                        return FALSE;
                }
        }
-       return this->cowfs->set_scenario(this->cowfs, dir);
+       return this->cowfs->set_overlay(this->cowfs, dir);
 }
 
 /**
@@ -425,10 +433,11 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
        this->public.create_iface_iterator = (iterator_t*(*)(guest_t*))create_iface_iterator;
        this->public.start = (void*)start;
        this->public.stop = (void*)stop;
-       this->public.set_scenario = (bool(*)(guest_t*, char *path))set_scenario;
+       this->public.get_console = (char*(*)(guest_t*,int))get_console;
+       this->public.load_template = (bool(*)(guest_t*, char *path))load_template;
        this->public.sigchild = (void(*)(guest_t*))sigchild;
        this->public.destroy = (void*)destroy;
-       
+               
        if (*parent == '/' || getcwd(cwd, sizeof(cwd)) == NULL)
        {
                asprintf(&this->dirname, "%s/%s", parent, name);