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

Commit d3cfa23

Browse files
authored
Merge pull request #139 from gao-feng/revert
Revert "move mount /proc to hyper_container_final_init()"
2 parents ae2d491 + 9bfb3be commit d3cfa23

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

src/container.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ struct port {
3333
struct hyper_container {
3434
struct list_head list;
3535
struct hyper_exec exec;
36-
int finalinit;
3736
int ns;
3837
uint32_t code;
3938

src/exec.c

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,20 @@ int hyper_watch_exec_pty(struct hyper_exec *exec, struct hyper_pod *pod)
476476
}
477477

478478
static int hyper_enter_container(struct hyper_pod *pod,
479-
struct hyper_container *c)
479+
struct hyper_exec *exec)
480480
{
481481
int ipcns, utsns, mntns, ret;
482+
struct hyper_container *c;
482483
char path[512];
483484

484485
ret = ipcns = utsns = mntns = -1;
485486

487+
c = hyper_find_container(pod, exec->id);
488+
if (c == NULL) {
489+
fprintf(stderr, "can not find container %s\n", exec->id);
490+
return -1;
491+
}
492+
486493
sprintf(path, "/proc/%d/ns/uts", pod->init_pid);
487494
utsns = open(path, O_RDONLY| O_CLOEXEC);
488495
if (utsns < 0) {
@@ -519,6 +526,12 @@ static int hyper_enter_container(struct hyper_pod *pod,
519526
/* TODO: wait for container finishing setup root */
520527
chdir("/");
521528

529+
/* already in pidns & mntns of container, mount proc filesystem */
530+
if (exec->init && mount("proc", "/proc", "proc", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) < 0) {
531+
perror("fail to mount proc filesystem for container");
532+
goto out;
533+
}
534+
522535
ret = 0;
523536
out:
524537
close(ipcns);
@@ -527,34 +540,12 @@ static int hyper_enter_container(struct hyper_pod *pod,
527540
return ret;
528541
}
529542

530-
static int hyper_container_final_init(struct hyper_container *c)
531-
{
532-
if (c->finalinit)
533-
return 0;
534-
535-
/* already in pidns & mntns of container, mount proc filesystem */
536-
if (mount("proc", "/proc", "proc", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) < 0) {
537-
perror("fail to mount proc filesystem for container");
538-
return -1;
539-
}
540-
541-
c->finalinit = 1;
542-
return 0;
543-
}
544-
545543
static int hyper_do_exec_cmd(struct hyper_exec *exec, struct hyper_pod *pod, int pipe)
546544
{
547545
int pid = -1, ret = -1;
548546
char path[512];
549-
struct hyper_container *c;
550547
int pidns;
551548

552-
c = hyper_find_container(pod, exec->id);
553-
if (c == NULL) {
554-
fprintf(stderr, "can not find container %s\n", exec->id);
555-
return -1;
556-
}
557-
558549
sprintf(path, "/proc/%d/ns/pid", pod->init_pid);
559550
pidns = open(path, O_RDONLY| O_CLOEXEC);
560551
if (pidns < 0) {
@@ -580,16 +571,11 @@ static int hyper_do_exec_cmd(struct hyper_exec *exec, struct hyper_pod *pod, int
580571
goto out;
581572
}
582573

583-
if (hyper_enter_container(pod, c) < 0) {
574+
if (hyper_enter_container(pod, exec) < 0) {
584575
fprintf(stderr, "enter container ns failed\n");
585576
goto exit;
586577
}
587578

588-
if (hyper_container_final_init(c)) {
589-
fprintf(stderr, "final container intialization failed\n");
590-
goto exit;
591-
}
592-
593579
// set early env. the container env config can overwrite it
594580
setenv("HOME", "/root", 1);
595581
setenv("HOSTNAME", pod->hostname, 1);

0 commit comments

Comments
 (0)