@@ -262,18 +262,27 @@ func parseKV(raw string) (string, uint64, error) {
262
262
// etc.
263
263
//
264
264
// The resulting map does not have an element for cgroup v2 unified hierarchy.
265
+ // Use ParseCgroupFileUnified to get the unified path.
265
266
func ParseCgroupFile (path string ) (map [string ]string , error ) {
267
+ x , _ , err := ParseCgroupFileUnified (path )
268
+ return x , err
269
+ }
270
+
271
+ // ParseCgroupFileUnified returns legacy subsystem paths as the first value,
272
+ // and returns the unified path as the second value.
273
+ func ParseCgroupFileUnified (path string ) (map [string ]string , string , error ) {
266
274
f , err := os .Open (path )
267
275
if err != nil {
268
- return nil , err
276
+ return nil , "" , err
269
277
}
270
278
defer f .Close ()
271
- return parseCgroupFromReader (f )
279
+ return parseCgroupFromReaderUnified (f )
272
280
}
273
281
274
- func parseCgroupFromReader (r io.Reader ) (map [string ]string , error ) {
282
+ func parseCgroupFromReaderUnified (r io.Reader ) (map [string ]string , string , error ) {
275
283
var (
276
284
cgroups = make (map [string ]string )
285
+ unified = ""
277
286
s = bufio .NewScanner (r )
278
287
)
279
288
for s .Scan () {
@@ -282,18 +291,20 @@ func parseCgroupFromReader(r io.Reader) (map[string]string, error) {
282
291
parts = strings .SplitN (text , ":" , 3 )
283
292
)
284
293
if len (parts ) < 3 {
285
- return nil , fmt .Errorf ("invalid cgroup entry: %q" , text )
294
+ return nil , unified , fmt .Errorf ("invalid cgroup entry: %q" , text )
286
295
}
287
296
for _ , subs := range strings .Split (parts [1 ], "," ) {
288
- if subs != "" {
297
+ if subs == "" {
298
+ unified = parts [2 ]
299
+ } else {
289
300
cgroups [subs ] = parts [2 ]
290
301
}
291
302
}
292
303
}
293
304
if err := s .Err (); err != nil {
294
- return nil , err
305
+ return nil , unified , err
295
306
}
296
- return cgroups , nil
307
+ return cgroups , unified , nil
297
308
}
298
309
299
310
func getCgroupDestination (subsystem string ) (string , error ) {
0 commit comments