MCPcopy Create free account
hub / github.com/containers/common / readFileByKeyAsUint64

Function readFileByKeyAsUint64

pkg/cgroups/cgroups.go:368–389  ·  view source on GitHub ↗
(path, key string)

Source from the content-addressed store, hash-verified

366}
367
368func readFileByKeyAsUint64(path, key string) (uint64, error) {
369 content, err := ioutil.ReadFile(path)
370 if err != nil {
371 return 0, err
372 }
373 for _, line := range strings.Split(string(content), "\n") {
374 fields := strings.SplitN(line, " ", 2)
375 if fields[0] == key {
376 v := cleanString(string(fields[1]))
377 if v == "max" {
378 return math.MaxUint64, nil
379 }
380 ret, err := strconv.ParseUint(v, 10, 64)
381 if err != nil {
382 return ret, errors.Wrapf(err, "parse %s from %s", v, path)
383 }
384 return ret, nil
385 }
386 }
387
388 return 0, fmt.Errorf("no key named %s from %s", key, path)
389}
390
391// New creates a new cgroup control
392func New(path string, resources *spec.LinuxResources) (*CgroupControl, error) {

Callers 1

StatMethod · 0.85

Calls 1

cleanStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…