]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
bdev: Fix aufs mounts when /run/lxc doesn't exist
authorStéphane Graber <stgraber@ubuntu.com>
Thu, 20 Feb 2014 15:06:30 +0000 (10:06 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 20 Feb 2014 15:22:29 +0000 (10:22 -0500)
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/bdev.c

index 3357ad2e9be7f55d8d58565dd511a9b78779d4d5..587f0672a3fb412a408e90abce8ea5cbef96c47f 100644 (file)
@@ -2068,6 +2068,7 @@ static int aufs_mount(struct bdev *bdev)
        int len;
        unsigned long mntflags;
        char *mntdata;
+       char *runpath;
        int ret;
 
        if (strcmp(bdev->type, "aufs"))
@@ -2098,19 +2099,31 @@ static int aufs_mount(struct bdev *bdev)
        if (!rundir)
                return -1;
 
+       len = strlen(rundir) + strlen("/lxc") + 1;
+       runpath = alloca(len);
+       ret = snprintf(runpath, len, "%s/lxc", rundir);
+       if (ret < 0 || ret >= len) {
+               free(mntdata);
+               return -1;
+       }
+       if (mkdir_p(runpath, 0755) < 0) {
+               free(mntdata);
+               return -1;
+       }
+
        // AUFS does not work on top of certain filesystems like (XFS or Btrfs)
        // so add xino=RUNDIR/lxc/aufs.xino parameter to mount options
        //
        // see http://www.mail-archive.com/aufs-users@lists.sourceforge.net/msg02587.html
        if (mntdata) {
-               len = strlen(lower) + strlen(upper) + strlen(rundir) + strlen("br==rw:=ro,,xino=/lxc/aufs.xino") + strlen(mntdata) + 1;
+               len = strlen(lower) + strlen(upper) + strlen(runpath) + strlen("br==rw:=ro,,xino=/aufs.xino") + strlen(mntdata) + 1;
                options = alloca(len);
-               ret = snprintf(options, len, "br=%s=rw:%s=ro,%s,xino=%s/lxc/aufs.xino", upper, lower, mntdata, rundir);
+               ret = snprintf(options, len, "br=%s=rw:%s=ro,%s,xino=%s/aufs.xino", upper, lower, mntdata, runpath);
        }
        else {
-               len = strlen(lower) + strlen(upper) + strlen(rundir) + strlen("br==rw:=ro,xino=/lxc/aufs.xino") + 1;
+               len = strlen(lower) + strlen(upper) + strlen(runpath) + strlen("br==rw:=ro,xino=/aufs.xino") + 1;
                options = alloca(len);
-               ret = snprintf(options, len, "br=%s=rw:%s=ro,xino=%s/lxc/aufs.xino", upper, lower, rundir);
+               ret = snprintf(options, len, "br=%s=rw:%s=ro,xino=%s/aufs.xino", upper, lower, runpath);
        }
 
        free(rundir);