do not create _data dir without checking first

container_populate_volume() checks _data existance to determine if it
should populate old data. We only need to create new _data with 0777
mode if there is no existing one. That includes two cases:
1. before populating old data in container_populate_volume()
2. mount an empty volume for the fist time

For file volume case, we need to chmod it instead, to make sure any user
is able to read/write the file.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
Peng Tao
2016-08-14 11:00:45 +08:00
parent 8a86dd1f51
commit de0c2c97e4
+14 -7
View File
@@ -41,7 +41,7 @@ static int container_populate_volume(char *src, char *dest)
return -1;
}
if (hyper_mkdir(dest, 0755) < 0) {
if (hyper_mkdir(dest, 0777) < 0) {
fprintf(stderr, "fail to create directroy %s\n", dest);
return -1;
}
@@ -61,6 +61,10 @@ static int container_check_file_volume(char *hyper_path, const char **filename)
*filename = NULL;
num = scandir(hyper_path, &list, NULL, NULL);
if (num < 0) {
/* No data in the volume yet, treat as non-file-volume */
if (errno == ENOENT) {
return 0;
}
perror("scan path failed");
return -1;
} else if (num != 3) {
@@ -122,12 +126,6 @@ static int container_setup_volume(struct hyper_container *container)
}
sprintf(volume, "/%s/_data", path);
/* 0777 so that any user can write to new volumes */
if (hyper_mkdir(volume, 0777) < 0) {
fprintf(stderr, "fail to create directroy %s\n", volume);
return -1;
}
if (container_check_file_volume(volume, &filevolume) < 0)
return -1;
@@ -142,6 +140,10 @@ static int container_setup_volume(struct hyper_container *container)
fprintf(stderr, "fail to populate volume %s\n", mountpoint);
return -1;
}
} else if (hyper_mkdir(volume, 0777) < 0) {
/* First time mounting an empty volume */
perror("create _data dir failed");
return -1;
}
} else {
hyper_filize(mountpoint);
@@ -150,6 +152,11 @@ static int container_setup_volume(struct hyper_container *container)
return -1;
}
sprintf(volume, "/%s/_data/%s", path, filevolume);
/* 0777 so that any user can read/write the new file volume */
if (chmod(volume, 0777) < 0) {
fprintf(stderr, "fail to chmod directroy %s\n", volume);
return -1;
}
}
if (mount(volume, mountpoint, NULL, MS_BIND, NULL) < 0) {