@@ -789,15 +789,52 @@ struct hyper_container *hyper_find_container(struct hyper_pod *pod, const char *
789789 return NULL ;
790790}
791791
792- void hyper_cleanup_container (struct hyper_container * c , struct hyper_pod * pod )
792+ static void hyper_cleanup_container_mounts (struct hyper_container * container , struct hyper_pod * pod )
793793{
794- char root [ 512 ] ;
794+ int pid , pipe [ 2 ] = { -1 , -1 } ;
795795
796- sprintf (root , "/tmp/hyper/%s/devpts/" , c -> id );
797- if (umount (root ) < 0 && umount2 (root , MNT_DETACH ))
798- perror ("umount devpts failed" );
796+ if (pipe2 (pipe , O_CLOEXEC ) < 0 ) {
797+ perror ("create pipe for unmount failed" );
798+ return ;
799+ }
800+
801+ pid = fork ();
802+ if (pid < 0 ) {
803+ perror ("fork unmount process failed" );
804+ goto out ;
805+ } else if (pid == 0 ) {
806+ if (hyper_enter_sandbox (pod , -1 ) < 0 ) {
807+ hyper_send_type (pipe [1 ], -1 );
808+ _exit (-1 );
809+ }
810+ if (setns (container -> ns , CLONE_NEWNS ) < 0 ) {
811+ perror ("fail to enter container ns" );
812+ hyper_send_type (pipe [1 ], -1 );
813+ _exit (-1 );
814+ }
815+ hyper_unmount_all ();
816+ hyper_send_type (pipe [1 ], 0 );
817+ _exit (0 );
818+ }
819+ hyper_get_type (pipe [0 ], (uint32_t * )& pid );
799820
821+ out :
822+ close (pipe [0 ]);
823+ close (pipe [1 ]);
824+ }
825+
826+ void hyper_cleanup_container (struct hyper_container * c , struct hyper_pod * pod )
827+ {
828+ hyper_cleanup_container_mounts (c , pod );
800829 close (c -> ns );
801830 hyper_cleanup_container_portmapping (c , pod );
802831 hyper_free_container (c );
803832}
833+
834+ void hyper_cleanup_mounts (struct hyper_pod * pod )
835+ {
836+ struct hyper_container * c ;
837+
838+ list_for_each_entry (c , & pod -> containers , list )
839+ hyper_cleanup_container_mounts (c , pod );
840+ }
0 commit comments