do container_setup_dns() before move the rootfs

Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
Lai Jiangshan
2016-04-03 19:09:11 +08:00
parent 5be2a71a84
commit b441c1bffe
+9 -9
View File
@@ -277,7 +277,7 @@ static int container_setup_dns(struct hyper_container *container)
{
int fd;
struct stat st;
char *src = "/.oldroot/tmp/hyper/resolv.conf";
char *src = "/tmp/hyper/resolv.conf";
if (stat(src, &st) < 0) {
if (errno == ENOENT) {
@@ -289,16 +289,16 @@ static int container_setup_dns(struct hyper_container *container)
return -1;
}
hyper_mkdir("/etc");
hyper_mkdir("./etc");
fd = open("/etc/resolv.conf", O_CREAT| O_WRONLY, 0644);
fd = open("./etc/resolv.conf", O_CREAT| O_WRONLY, 0644);
if (fd < 0) {
perror("create /etc/resolv.conf failed");
return -1;
}
close(fd);
if (mount(src, "/etc/resolv.conf", NULL, MS_BIND, NULL) < 0) {
if (mount(src, "./etc/resolv.conf", NULL, MS_BIND, NULL) < 0) {
perror("bind to /etc/resolv.conf failed");
return -1;
}
@@ -493,6 +493,11 @@ static int hyper_container_init(void *data)
goto fail;
}
if (container_setup_dns(container) < 0) {
fprintf(stderr, "container sets up dns failed\n");
goto fail;
}
// manipulate the rootfs of the container/namespace: move the prepared path @rootfs to /
if (mount(rootfs, "/", NULL, MS_MOVE, NULL) < 0) {
perror("failed to move rootfs");
@@ -509,11 +514,6 @@ static int hyper_container_init(void *data)
goto fail;
}
if (container_setup_dns(container) < 0) {
fprintf(stderr, "container sets up dns failed\n");
goto fail;
}
if (container_setup_workdir(container) < 0) {
fprintf(stderr, "container sets up work directory failed\n");
goto fail;