diff options
author | Tim Deegan <Tim.Deegan@xensource.com> | 2007-07-26 12:00:32 +0100 |
---|---|---|
committer | Tim Deegan <Tim.Deegan@xensource.com> | 2007-07-26 12:00:32 +0100 |
commit | 2abe070373048a47d66851e76593c11f95683059 (patch) | |
tree | 5730170c10c893ab6c74e36a83bffe75cc0666df /tools/xcutils | |
parent | 504e6b5eae079a93ac47fe2f1a228db6ff9b1aca (diff) | |
download | xen-2abe070373048a47d66851e76593c11f95683059.tar.gz xen-2abe070373048a47d66851e76593c11f95683059.tar.bz2 xen-2abe070373048a47d66851e76593c11f95683059.zip |
[HVM] Save/restore: don't leak shared-memory segments after HVM live-migrate.
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
Diffstat (limited to 'tools/xcutils')
-rw-r--r-- | tools/xcutils/xc_save.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/tools/xcutils/xc_save.c b/tools/xcutils/xc_save.c index 188ea7b72e..3a97683a97 100644 --- a/tools/xcutils/xc_save.c +++ b/tools/xcutils/xc_save.c @@ -54,8 +54,18 @@ static int suspend(int domid) static char *qemu_active_path; static char *qemu_next_active_path; +static int qemu_shmid = -1; static struct xs_handle *xs; + +/* Mark the shared-memory segment for destruction */ +static void qemu_destroy_buffer(void) +{ + if (qemu_shmid != -1) + shmctl(qemu_shmid, IPC_RMID, NULL); + qemu_shmid = -1; +} + /* Get qemu to change buffers. */ static void qemu_flip_buffer(int domid, int next_active) { @@ -97,22 +107,23 @@ static void * init_qemu_maps(int domid, unsigned int bitmap_size) { key_t key; char key_ascii[17] = {0,}; - int shmid = -1; void *seg; char *path, *p; /* Make a shared-memory segment */ - while (shmid == -1) - { + do { key = rand(); /* No security, just a sequence of numbers */ - shmid = shmget(key, 2 * bitmap_size, + qemu_shmid = shmget(key, 2 * bitmap_size, IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR); - if (shmid == -1 && errno != EEXIST) + if (qemu_shmid == -1 && errno != EEXIST) errx(1, "can't get shmem to talk to qemu-dm"); - } + } while (qemu_shmid == -1); + + /* Remember to tidy up after ourselves */ + atexit(qemu_destroy_buffer); /* Map it into our address space */ - seg = shmat(shmid, NULL, 0); + seg = shmat(qemu_shmid, NULL, 0); if (seg == (void *) -1) errx(1, "can't map shmem to talk to qemu-dm"); memset(seg, 0, 2 * bitmap_size); |