src/linux/cgroups.cpp
// Read a control file. Control files are the gateway to monitor and control
// cgroups. This function assumes the cgroups virtual file systems are properly
// mounted on the given hierarchy, and the given cgroup has been already created
// properly. The given control file name should also be valid.
// @param   hierarchy   Path to the hierarchy root.
// @param   cgroup      Path to the cgroup relative to the hierarchy root.
// @param   control     Name of the control file.
// @return  The value read from the control file.
Read a control file. Control files are the gateway to monitor and control
cgroups. This function assumes the cgroups virtual file systems are properly
mounted on the given hierarchy, and the given cgroup has been already created
properly. The given control file name should also be valid.
Read a control file . Control files are the gateway to monitor and control cgroups . This function assumes the cgroups virtual file systems are properly mounted on the given hierarchy and the given cgroup has been already created properly . The given control file name should also be valid .
static Try<std::string> readControl(const std::string& hierarchy,
                                    const std::string& cgroup,
                                    const std::string& control)
{
  std::string path = hierarchy + "/" + cgroup + "/" + control;
  std::ifstream file(path.c_str());
  if (!file.is_open()) {
    return Try<std::string>::error("Failed to open file " + path);
  }
  std::ostringstream ss;
  ss << file.rdbuf();
  if (file.fail()) {
    std::string msg = strerror(errno);
    file.close();
    return Try<std::string>::error(msg);
  }
  file.close();
  return ss.str();
}
static Try < std :: string > readControl ( const std :: string & hierarchy , const std :: string & cgroup , const std :: string & control ) { std :: string path = hierarchy + " " + cgroup + " " + control ; std :: ifstream file ( path . c_str ( ) ) ; if ( ! file . is_open ( ) ) { return Try < std :: string > :: error ( " " + path ) ; } std :: ostringstream ss ; ss << file . rdbuf ( ) ; if ( file . fail ( ) ) { std :: string msg = strerror ( errno ) ; file . close ( ) ; return Try < std :: string > :: error ( msg ) ; } file . close ( ) ; return ss . str ( ) ; }
Read a control file.
Read a control file .
// We do not use os::read here because it cannot correctly read proc or // cgroups control files (lseek will return error). // TODO(jieyu): Make sure that the way we get errno here is portable.