File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main
22
33import (
44 "bytes"
5+ "bufio"
56 "encoding/json"
67 "fmt"
78 "io"
@@ -244,6 +245,45 @@ func validateROPaths(spec *rspec.Spec) error {
244245 return nil
245246}
246247
248+ func getThisCgroupPath (subsystem string ) (string , error ) {
249+ f , err := os .Open ("/proc/self/cgroup" )
250+ if err != nil {
251+ return "" , err
252+ }
253+ defer f .Close ()
254+
255+ s := bufio .NewScanner (f )
256+ for s .Scan () {
257+ if err := s .Err (); err != nil {
258+ return "" , err
259+ }
260+
261+ text := s .Text ()
262+ parts := strings .Split (text , ":" )
263+
264+ for _ , subs := range strings .Split (parts [1 ], "," ) {
265+ if subs == subsystem {
266+ return parts [2 ], nil
267+ }
268+ }
269+ }
270+ return "" , fmt .Errorf ("cgroup %v not found" , subsystem )
271+ }
272+
273+ func validateCgroupsPath (spec * rspec.Spec ) error {
274+ fmt .Println ("validating cgroupsPath" )
275+ expectedPath := spec .Linux .CgroupsPath
276+ actualPath , err := getThisCgroupPath ("devices" )
277+ if err != nil {
278+ return err
279+ }
280+
281+ if expectedPath != nil && * expectedPath != actualPath {
282+ return fmt .Errorf ("Cgroup path expected: %v, actual: %v" , * expectedPath , actualPath )
283+ }
284+ return nil
285+ }
286+
247287func main () {
248288 spec , err := loadSpecConfig ()
249289 if err != nil {
@@ -254,6 +294,7 @@ func main() {
254294 validateRootFS ,
255295 validateProcess ,
256296 validateCapabilities ,
297+ validateCgroupsPath ,
257298 validateHostname ,
258299 validateRlimits ,
259300 validateSysctls ,
You can’t perform that action at this time.
0 commit comments