66#include <sys/stat.h>
77#include <sys/epoll.h>
88#include <sys/ioctl.h>
9- #include <sys/mount.h>
109#include <sys/wait.h>
1110#include <sys/socket.h>
1211#include <dirent.h>
@@ -479,7 +478,6 @@ static int hyper_setup_stdio_events(struct hyper_exec *exec, struct stdio_config
479478static int hyper_do_exec_cmd (struct hyper_exec * exec , int pipe , struct stdio_config * io )
480479{
481480 struct hyper_container * c ;
482- int ret ;
483481
484482 if (hyper_enter_sandbox (exec -> pod , pipe ) < 0 ) {
485483 perror ("enter pidns of pod init failed" );
@@ -497,46 +495,11 @@ static int hyper_do_exec_cmd(struct hyper_exec *exec, int pipe, struct stdio_con
497495 perror ("fail to enter container ns" );
498496 goto out ;
499497 }
500-
501- /* c->pid_ns is set in hyper_run_process based off the pid sent over the pipe */
502- if (c -> pid_ns > 0 ) {
503- if (setns (c -> pid_ns , CLONE_NEWPID ) < 0 ) {
504- perror ("fail to enter container pid ns" );
505- goto out ;
506- }
507- } else {
508- if (unshare (CLONE_NEWPID ) < 0 ) {
509- perror ("failed to create new pid ns" );
510- goto out ;
511- }
512- }
513-
514- /* current process isn't in the pidns even though setns(pidns, CLONE_NEWPID)
515- * was called. fork() is needed, so that the child process will run in
516- * the pidns, see man 2 setns */
517- ret = fork ();
518- if (ret < 0 ) {
519- perror ("failed to fork" );
520- goto out ;
521- } else if (ret > 0 ) {
522- fprintf (stdout , "created child process pid=%d in the sandbox\n" , ret );
523- if (pipe > 0 ) {
524- hyper_send_type (pipe , ret );
525- }
526- _exit (0 );
527- }
528-
529498 if (chdir ("/" ) < 0 ) {
530499 perror ("fail to change to the root of the rootfs" );
531500 goto out ;
532501 }
533502
534- /* iff creating new pid namespace remount /proc inside */
535- if (c -> pid_ns == -1 && mount ("proc" , "/proc" , "proc" , MS_NOSUID | MS_NODEV | MS_NOEXEC , NULL ) < 0 ) {
536- perror ("failed to mount /proc after pid namespace switch" );
537- goto out ;
538- }
539-
540503 // Clear process environment
541504 clearenv ();
542505
@@ -649,8 +612,6 @@ int hyper_run_process(struct hyper_exec *exec)
649612 int pid , ret = -1 ;
650613 uint32_t type ;
651614 struct stdio_config io = {-1 , -1 ,-1 , -1 ,-1 , -1 };
652- struct hyper_container * c ;
653- char path [128 ];
654615
655616 if (exec -> argv == NULL || exec -> seq == 0 || exec -> container_id == NULL || strlen (exec -> container_id ) == 0 ) {
656617 fprintf (stderr , "cmd is %p, seq %" PRIu64 ", container %s\n" ,
@@ -687,21 +648,6 @@ int hyper_run_process(struct hyper_exec *exec)
687648 goto close_tty ;
688649 }
689650
690- c = hyper_find_container (exec -> pod , exec -> container_id );
691- if (c == NULL ) {
692- fprintf (stderr , "can not find container %s\n" , exec -> container_id );
693- goto out ;
694- }
695-
696- if (c -> pid_ns < 0 ) {
697- sprintf (path , "/proc/%d/ns/pid" , type );
698- c -> pid_ns = open (path , O_RDONLY | O_CLOEXEC );
699- if (c -> pid_ns < 0 ) {
700- perror ("open container pid ns failed" );
701- goto close_tty ;
702- }
703- }
704-
705651 if (hyper_setup_stdio_events (exec , & io ) < 0 ) {
706652 fprintf (stderr , "add pts master event failed\n" );
707653 goto close_tty ;
0 commit comments