@@ -139,7 +139,7 @@ func (m Mount) GetThisCgroupDir(cgroups map[string]string) (string, error) {
139139 return getControllerPath (m .Subsystems [0 ], cgroups )
140140}
141141
142- func getCgroupMountsHelper (ss map [string ]bool , mi io.Reader ) ([]Mount , error ) {
142+ func getCgroupMountsHelper (ss map [string ]bool , mi io.Reader , all bool ) ([]Mount , error ) {
143143 res := make ([]Mount , 0 , len (ss ))
144144 scanner := bufio .NewScanner (mi )
145145 numFound := 0
@@ -166,7 +166,9 @@ func getCgroupMountsHelper(ss map[string]bool, mi io.Reader) ([]Mount, error) {
166166 } else {
167167 m .Subsystems = append (m .Subsystems , opt )
168168 }
169- numFound ++
169+ if ! all {
170+ numFound ++
171+ }
170172 }
171173 res = append (res , m )
172174 }
@@ -176,23 +178,25 @@ func getCgroupMountsHelper(ss map[string]bool, mi io.Reader) ([]Mount, error) {
176178 return res , nil
177179}
178180
179- func GetCgroupMounts () ([]Mount , error ) {
181+ // GetCgroupMounts returns the mounts for the cgroup subsystems.
182+ // all indicates whether to return just the first instance or all the mounts.
183+ func GetCgroupMounts (all bool ) ([]Mount , error ) {
180184 f , err := os .Open ("/proc/self/mountinfo" )
181185 if err != nil {
182186 return nil , err
183187 }
184188 defer f .Close ()
185189
186- all , err := ParseCgroupFile ("/proc/self/cgroup" )
190+ allSubsystems , err := ParseCgroupFile ("/proc/self/cgroup" )
187191 if err != nil {
188192 return nil , err
189193 }
190194
191195 allMap := make (map [string ]bool )
192- for s := range all {
196+ for s := range allSubsystems {
193197 allMap [s ] = true
194198 }
195- return getCgroupMountsHelper (allMap , f )
199+ return getCgroupMountsHelper (allMap , f , all )
196200}
197201
198202// GetAllSubsystems returns all the cgroup subsystems supported by the kernel
0 commit comments