Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit de0c2c9

Browse files
committed
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 <[email protected]>
1 parent 8a86dd1 commit de0c2c9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/container.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int container_populate_volume(char *src, char *dest)
4141
return -1;
4242
}
4343

44-
if (hyper_mkdir(dest, 0755) < 0) {
44+
if (hyper_mkdir(dest, 0777) < 0) {
4545
fprintf(stderr, "fail to create directroy %s\n", dest);
4646
return -1;
4747
}
@@ -61,6 +61,10 @@ static int container_check_file_volume(char *hyper_path, const char **filename)
6161
*filename = NULL;
6262
num = scandir(hyper_path, &list, NULL, NULL);
6363
if (num < 0) {
64+
/* No data in the volume yet, treat as non-file-volume */
65+
if (errno == ENOENT) {
66+
return 0;
67+
}
6468
perror("scan path failed");
6569
return -1;
6670
} else if (num != 3) {
@@ -122,12 +126,6 @@ static int container_setup_volume(struct hyper_container *container)
122126
}
123127

124128
sprintf(volume, "/%s/_data", path);
125-
/* 0777 so that any user can write to new volumes */
126-
if (hyper_mkdir(volume, 0777) < 0) {
127-
fprintf(stderr, "fail to create directroy %s\n", volume);
128-
return -1;
129-
}
130-
131129
if (container_check_file_volume(volume, &filevolume) < 0)
132130
return -1;
133131

@@ -142,6 +140,10 @@ static int container_setup_volume(struct hyper_container *container)
142140
fprintf(stderr, "fail to populate volume %s\n", mountpoint);
143141
return -1;
144142
}
143+
} else if (hyper_mkdir(volume, 0777) < 0) {
144+
/* First time mounting an empty volume */
145+
perror("create _data dir failed");
146+
return -1;
145147
}
146148
} else {
147149
hyper_filize(mountpoint);
@@ -150,6 +152,11 @@ static int container_setup_volume(struct hyper_container *container)
150152
return -1;
151153
}
152154
sprintf(volume, "/%s/_data/%s", path, filevolume);
155+
/* 0777 so that any user can read/write the new file volume */
156+
if (chmod(volume, 0777) < 0) {
157+
fprintf(stderr, "fail to chmod directroy %s\n", volume);
158+
return -1;
159+
}
153160
}
154161

155162
if (mount(volume, mountpoint, NULL, MS_BIND, NULL) < 0) {

0 commit comments

Comments
 (0)