aboutsummaryrefslogtreecommitdiffstats
path: root/src/dumm/guest.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2007-07-27 07:37:15 +0000
committerMartin Willi <martin@strongswan.org>2007-07-27 07:37:15 +0000
commit539a55a44189e57694e65cf75f5e1040a7fdd37d (patch)
treebfaf9a24855c65090500ba89fd4f4322cd8d62e4 /src/dumm/guest.c
parent5b608fd7cac56eec62e69836fc01886f101b7f85 (diff)
downloadstrongswan-539a55a44189e57694e65cf75f5e1040a7fdd37d.tar.bz2
strongswan-539a55a44189e57694e65cf75f5e1040a7fdd37d.tar.xz
support for killing guests properly
Diffstat (limited to 'src/dumm/guest.c')
-rw-r--r--src/dumm/guest.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/dumm/guest.c b/src/dumm/guest.c
index dc97c2d57..59e501478 100644
--- a/src/dumm/guest.c
+++ b/src/dumm/guest.c
@@ -78,7 +78,7 @@ static iface_t* create_iface(private_guest_t *this, char *name)
iterator_t *iterator;
iface_t *iface;
- if (this->pid == 0)
+ if (this->state != GUEST_RUNNING)
{
DBG1("guest '%s' not running, unable to add interface", this->name);
return NULL;
@@ -225,14 +225,29 @@ static bool start(private_guest_t *this, char *kernel)
*/
static void stop(private_guest_t *this)
{
- if (this->pid)
+ if (this->state != GUEST_STOPPED)
{
+ this->ifaces->destroy_offset(this->ifaces, offsetof(iface_t, destroy));
+ this->ifaces = linked_list_create();
kill(this->pid, SIGINT);
- this->pid = 0;
+ this->state = GUEST_STOPPING;
+ while (this->state == GUEST_STOPPING)
+ {
+ sched_yield();
+ }
}
}
/**
+ * Implementation of guest_t.sigchild.
+ */
+static void sigchild(private_guest_t *this)
+{
+ this->state = GUEST_STOPPED;
+ this->pid = 0;
+}
+
+/**
* Check if directory exists, create otherwise
*/
static bool makedir(char *dir, char *name)
@@ -326,7 +341,6 @@ static void destroy(private_guest_t *this)
{
stop(this);
umount_unionfs(this->name);
- this->ifaces->destroy_offset(this->ifaces, offsetof(iface_t, destroy));
DESTROY_IF(this->mconsole);
free(this->name);
free(this->master);
@@ -347,6 +361,7 @@ guest_t *guest_create(char *name, char *master, int mem)
this->public.create_iface_iterator = (iterator_t*(*)(guest_t*))create_iface_iterator;
this->public.start = (void*)start;
this->public.stop = (void*)stop;
+ this->public.sigchild = (void(*)(guest_t*))sigchild;
this->public.destroy = (void*)destroy;
if (!makedir(HOST_DIR, name) || !makedir(MOUNT_DIR, name) ||