@@ -789,15 +789,52 @@ struct hyper_container *hyper_find_container(struct hyper_pod *pod, const char *
789
789
return NULL ;
790
790
}
791
791
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 )
793
793
{
794
- char root [ 512 ] ;
794
+ int pid , pipe [ 2 ] = { -1 , -1 } ;
795
795
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 );
799
820
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 );
800
829
close (c -> ns );
801
830
hyper_cleanup_container_portmapping (c , pod );
802
831
hyper_free_container (c );
803
832
}
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