@@ -853,6 +853,10 @@ func testCgroupParent(t *testing.T, sb integration.Sandbox) {
853
853
t .SkipNow ()
854
854
}
855
855
856
+ if _ , err := os .Lstat ("/sys/fs/cgroup/cgroup.subtree_control" ); os .IsNotExist (err ) {
857
+ t .Skipf ("test requires cgroup v2" )
858
+ }
859
+
856
860
c , err := New (sb .Context (), sb .Address ())
857
861
require .NoError (t , err )
858
862
defer c .Close ()
@@ -864,8 +868,21 @@ func testCgroupParent(t *testing.T, sb integration.Sandbox) {
864
868
st = img .Run (append (ro , llb .Shlex (cmd ), llb .Dir ("/wd" ))... ).AddMount ("/wd" , st )
865
869
}
866
870
867
- run (`sh -c "cat /proc/self/cgroup > first"` , llb .WithCgroupParent ("foocgroup" ))
868
- run (`sh -c "cat /proc/self/cgroup > second"` )
871
+ cgroupName := "test." + identity .NewID ()
872
+
873
+ err = os .MkdirAll (filepath .Join ("/sys/fs/cgroup" , cgroupName ), 0755 )
874
+ require .NoError (t , err )
875
+
876
+ defer func () {
877
+ err := os .RemoveAll (filepath .Join ("/sys/fs/cgroup" , cgroupName ))
878
+ require .NoError (t , err )
879
+ }()
880
+
881
+ err = os .WriteFile (filepath .Join ("/sys/fs/cgroup" , cgroupName , "pids.max" ), []byte ("10" ), 0644 )
882
+ require .NoError (t , err )
883
+
884
+ run (`sh -c "(for i in $(seq 1 10); do sleep 1 & done 2>first.error); cat /proc/self/cgroup >> first"` , llb .WithCgroupParent (cgroupName ))
885
+ run (`sh -c "(for i in $(seq 1 10); do sleep 1 & done 2>second.error); cat /proc/self/cgroup >> second"` )
869
886
870
887
def , err := st .Marshal (sb .Context ())
871
888
require .NoError (t , err )
@@ -882,13 +899,22 @@ func testCgroupParent(t *testing.T, sb integration.Sandbox) {
882
899
}, nil )
883
900
require .NoError (t , err )
884
901
902
+ // neither process leaks parent cgroup name inside container
885
903
dt , err := os .ReadFile (filepath .Join (destDir , "first" ))
886
904
require .NoError (t , err )
887
- require .Contains (t , strings .TrimSpace (string (dt )), `/foocgroup/buildkit/` )
905
+ require .NotContains (t , strings .TrimSpace (string (dt )), cgroupName )
888
906
889
907
dt2 , err := os .ReadFile (filepath .Join (destDir , "second" ))
890
908
require .NoError (t , err )
891
- require .NotContains (t , strings .TrimSpace (string (dt2 )), `/foocgroup/buildkit/` )
909
+ require .NotContains (t , strings .TrimSpace (string (dt2 )), cgroupName )
910
+
911
+ dt , err = os .ReadFile (filepath .Join (destDir , "first.error" ))
912
+ require .NoError (t , err )
913
+ require .Contains (t , strings .TrimSpace (string (dt )), "Resource temporarily unavailable" )
914
+
915
+ dt , err = os .ReadFile (filepath .Join (destDir , "second.error" ))
916
+ require .NoError (t , err )
917
+ require .Equal (t , strings .TrimSpace (string (dt )), "" )
892
918
}
893
919
894
920
func testNetworkMode (t * testing.T , sb integration.Sandbox ) {
0 commit comments