// cgroup root for the given statgroup. (This will avoid falling back
// to host-level stats during container setup and teardown.)
func OpenStatFile(stderr chan<- string, cgroup Cgroup, statgroup string, stat string) (*os.File, error) {
+ var paths = []string{}
+ paths = append(paths, fmt.Sprintf("%s/%s/%s/%s/%s", cgroup.root, statgroup, cgroup.parent, cgroup.cid, stat))
+ paths = append(paths, fmt.Sprintf("%s/%s/%s/%s", cgroup.root, cgroup.parent, cgroup.cid, stat))
+ paths = append(paths, fmt.Sprintf("%s/%s/%s", cgroup.root, statgroup, stat))
+ paths = append(paths, fmt.Sprintf("%s/%s", cgroup.root, stat))
var path string
- path = fmt.Sprintf("%s/%s/%s/%s/%s", cgroup.root, statgroup, cgroup.parent, cgroup.cid, stat)
- file, err := os.Open(path)
- if err != nil {
- path = fmt.Sprintf("%s/%s/%s/%s", cgroup.root, cgroup.parent, cgroup.cid, stat)
- file, err = os.Open(path)
- }
- if err != nil {
- path = fmt.Sprintf("%s/%s/%s", cgroup.root, statgroup, stat)
+ var file *os.File
+ var err error
+ for _, path = range paths {
file, err = os.Open(path)
- }
- if err != nil {
- path = fmt.Sprintf("%s/%s", cgroup.root, stat)
- file, err = os.Open(path)
- }
- if err != nil {
- file = nil
- path = ""
+ if err == nil {
+ break
+ } else {
+ path = ""
+ }
}
if pathWas, ok := reportedStatFile[stat]; !ok || pathWas != path {
// Log whenever we start using a new/different cgroup