fn read_pid_cgroup_from_path>()

in below/procfs/src/lib.rs [622:647]


    fn read_pid_cgroup_from_path<P: AsRef<Path>>(path: P) -> Result<String> {
        let path = path.as_ref().join("cgroup");
        let file = File::open(&path).map_err(|e| Error::IoError(path.clone(), e))?;
        let buf_reader = BufReader::new(file);

        let mut cgroup_path = None;
        for line in buf_reader.lines() {
            let line = line.map_err(|e| Error::IoError(path.clone(), e))?;
            // Lines contain three colon separated fields:
            //   hierarchy-ID:controller-list:cgroup-path
            // A line starting with "0::" would be an entry for cgroup v2.
            // Otherwise, the line containing "pids" controller is what we want
            // for cgroup v1.
            let parts: Vec<_> = line.splitn(3, ':').collect();
            if parts.len() == 3 {
                if parts[0] == "0" && parts[1] == "" {
                    cgroup_path = Some(parts[2].to_owned());
                    // cgroup v2 takes precedence
                    break;
                } else if parts[1].split(',').any(|c| c == "pids") {
                    cgroup_path = Some(parts[2].to_owned());
                }
            }
        }
        cgroup_path.ok_or_else(|| Error::InvalidFileFormat(path))
    }