@@ -181,6 +181,10 @@ func readPids(path string, subsystem Name) ([]Process, error) {
181181 })
182182 }
183183 }
184+ if err := s .Err (); err != nil {
185+ // failed to read all pids?
186+ return nil , err
187+ }
184188 return out , nil
185189}
186190
@@ -208,6 +212,9 @@ func readTasksPids(path string, subsystem Name) ([]Task, error) {
208212 })
209213 }
210214 }
215+ if err := s .Err (); err != nil {
216+ return nil , err
217+ }
211218 return out , nil
212219}
213220
@@ -286,9 +293,6 @@ func parseCgroupFromReader(r io.Reader) (map[string]string, error) {
286293 s = bufio .NewScanner (r )
287294 )
288295 for s .Scan () {
289- if err := s .Err (); err != nil {
290- return nil , err
291- }
292296 var (
293297 text = s .Text ()
294298 parts = strings .SplitN (text , ":" , 3 )
@@ -302,6 +306,9 @@ func parseCgroupFromReader(r io.Reader) (map[string]string, error) {
302306 }
303307 }
304308 }
309+ if err := s .Err (); err != nil {
310+ return nil , err
311+ }
305312 return cgroups , nil
306313}
307314
@@ -313,16 +320,23 @@ func getCgroupDestination(subsystem string) (string, error) {
313320 defer f .Close ()
314321 s := bufio .NewScanner (f )
315322 for s .Scan () {
316- if err := s .Err (); err != nil {
317- return "" , err
323+ fields := strings .Split (s .Text (), " " )
324+ if len (fields ) < 10 {
325+ // broken mountinfo?
326+ continue
327+ }
328+ if fields [len (fields )- 3 ] != "cgroup" {
329+ continue
318330 }
319- fields := strings .Fields (s .Text ())
320331 for _ , opt := range strings .Split (fields [len (fields )- 1 ], "," ) {
321332 if opt == subsystem {
322333 return fields [3 ], nil
323334 }
324335 }
325336 }
337+ if err := s .Err (); err != nil {
338+ return "" , err
339+ }
326340 return "" , ErrNoCgroupMountDestination
327341}
328342
0 commit comments