]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
c/r: check for criu images in the checkpoint directory
authorTycho Andersen <tycho.andersen@canonical.com>
Fri, 24 Apr 2015 20:46:08 +0000 (14:46 -0600)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 1 Jul 2015 15:52:56 +0000 (11:52 -0400)
CRIU can get confused if there are two dumps that are written to the same
directory, so we make some minimal effort to prevent people from doing this.
This is a better alternative than forcing liblxc to create the directory, since
it is mostly race free (and neither solution is bullet proof anyway if someone
rsyncs some bad images over the top of the good ones).

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxccontainer.c

index 3171b24d6d4faaa097638ec563fe9a636420c07b..c0b264c813fcd94191ddd6c74f35c8544a97d8da 100644 (file)
@@ -3680,6 +3680,7 @@ static bool do_lxcapi_checkpoint(struct lxc_container *c, char *directory, bool
 {
        pid_t pid;
        int status;
+       char path[PATH_MAX];
 
        if (!criu_ok(c))
                return false;
@@ -3687,6 +3688,15 @@ static bool do_lxcapi_checkpoint(struct lxc_container *c, char *directory, bool
        if (mkdir(directory, 0700) < 0 && errno != EEXIST)
                return false;
 
+       status = snprintf(path, sizeof(path), "%s/inventory.img", directory);
+       if (status < 0 || status >= sizeof(path))
+               return false;
+
+       if (access(path, F_OK) == 0) {
+               ERROR("please use a fresh directory for the dump directory\n");
+               return false;
+       }
+
        if (!dump_net_info(c, directory))
                return false;