@@ -21,7 +21,6 @@ func (s *CpusetGroup) Apply(d *data) error {
2121 if err != nil && ! cgroups .IsNotFound (err ) {
2222 return err
2323 }
24-
2524 return s .ApplyDir (dir , d .c , d .pid )
2625}
2726
@@ -31,13 +30,11 @@ func (s *CpusetGroup) Set(path string, cgroup *configs.Cgroup) error {
3130 return err
3231 }
3332 }
34-
3533 if cgroup .CpusetMems != "" {
3634 if err := writeFile (path , "cpuset.mems" , cgroup .CpusetMems ); err != nil {
3735 return err
3836 }
3937 }
40-
4138 return nil
4239}
4340
@@ -55,10 +52,13 @@ func (s *CpusetGroup) ApplyDir(dir string, cgroup *configs.Cgroup, pid int) erro
5552 if dir == "" {
5653 return nil
5754 }
58- if err := s .ensureParent (dir ); err != nil {
55+ root , err := getCgroupRoot ()
56+ if err != nil {
57+ return err
58+ }
59+ if err := s .ensureParent (dir , root ); err != nil {
5960 return err
6061 }
61-
6262 // because we are not using d.join we need to place the pid into the procs file
6363 // unlike the other subsystems
6464 if err := writeFile (dir , "cgroup.procs" , strconv .Itoa (pid )); err != nil {
@@ -84,22 +84,17 @@ func (s *CpusetGroup) getSubsystemSettings(parent string) (cpus []byte, mems []b
8484 return cpus , mems , nil
8585}
8686
87- // ensureParent ensures that the parent directory of current is created
88- // with the proper cpus and mems files copied from it's parent if the values
89- // are a file with a new line char
90- func (s * CpusetGroup ) ensureParent (current string ) error {
87+ // ensureParent makes sure that the parent directory of current is created
88+ // and populated with the proper cpus and mems files copied from
89+ // it's parent.
90+ func (s * CpusetGroup ) ensureParent (current , root string ) error {
9191 parent := filepath .Dir (current )
92-
93- if _ , err := os .Stat (parent ); err != nil {
94- if ! os .IsNotExist (err ) {
95- return err
96- }
97-
98- if err := s .ensureParent (parent ); err != nil {
99- return err
100- }
92+ if filepath .Clean (parent ) == root {
93+ return nil
94+ }
95+ if err := s .ensureParent (parent , root ); err != nil {
96+ return err
10197 }
102-
10398 if err := os .MkdirAll (current , 0755 ); err != nil && ! os .IsExist (err ) {
10499 return err
105100 }
0 commit comments