src/linux/cgroups.cpp
// In cgroups, there is mechanism which allows to get notifications about
// changing status of a cgroup. It is based on Linux eventfd. See more
// information in the kernel documentation ("Notification API"). This function
// will create an eventfd and write appropriate control file to correlate the
// eventfd with a type of event so that users can start polling on the eventfd
// to get notified. It returns the eventfd (file descriptor) if the notifier has
// been successfully opened. This function assumes all the parameters are valid.
// The eventfd is set to be non-blocking.
// @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.
// @param   args        Control specific arguments.
// @return  The eventfd if the operation succeeds.
//          Error if the operation fails.
In cgroups, there is mechanism which allows to get notifications about
changing status of a cgroup. It is based on Linux eventfd. See more
information in the kernel documentation ("Notification API"). This function
will create an eventfd and write appropriate control file to correlate the
eventfd with a type of event so that users can start polling on the eventfd
to get notified. It returns the eventfd (file descriptor) if the notifier has
been successfully opened. This function assumes all the parameters are valid.
The eventfd is set to be non-blocking.
In cgroups there is mechanism which allows to get notifications about changing status of a cgroup . It is based on Linux eventfd . See more information in the kernel documentation ( " Notification API " ) . This function will create an eventfd and write appropriate control file to correlate the eventfd with a type of event so that users can start polling on the eventfd to get notified . It returns the eventfd ( file descriptor ) if the notifier has been successfully opened . This function assumes all the parameters are valid . The eventfd is set to be non - blocking .
static Try<int> openNotifier(const std::string& hierarchy,
                             const std::string& cgroup,
                             const std::string& control,
                             const Option<std::string>& args =
                               Option<std::string>::none())
{
  int efd = internal::eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
  if (efd < 0) {
    return Try<int>::error(
        "Create eventfd failed: " + std::string(strerror(errno)));
  }
  std::string path = hierarchy + "/" + cgroup + "/" + control;
  Try<int> cfd = os::open(path, O_RDWR);
  if (cfd.isError()) {
    os::close(efd);
    return Try<int>::error(cfd.error());
  }
  std::ostringstream out;
  out << std::dec << efd << " " << cfd.get();
  if (args.isSome()) {
    out << " " << args.get();
  }
  Try<Nothing> write = internal::writeControl(hierarchy,
                                              cgroup,
                                              "cgroup.event_control",
                                              out.str());
  if (write.isError()) {
    os::close(efd);
    os::close(cfd.get());
    return Try<int>::error(write.error());
  }
  os::close(cfd.get());
  return efd;
}
static Try < int > openNotifier ( const std :: string & hierarchy , const std :: string & cgroup , const std :: string & control , const Option < std :: string > & args = Option < std :: string > :: none ( ) ) { int efd = internal :: eventfd ( 0 , EFD_CLOEXEC | EFD_NONBLOCK ) ; if ( efd < 0 ) { return Try < int > :: error ( " " + std :: string ( strerror ( errno ) ) ) ; } std :: string path = hierarchy + " " + cgroup + " " + control ; Try < int > cfd = os :: open ( path , O_RDWR ) ; if ( cfd . isError ( ) ) { os :: close ( efd ) ; return Try < int > :: error ( cfd . error ( ) ) ; } std :: ostringstream out ; out << std :: dec << efd << " " << cfd . get ( ) ; if ( args . isSome ( ) ) { out << " " << args . get ( ) ; } Try < Nothing > write = internal :: writeControl ( hierarchy , cgroup , " " , out . str ( ) ) ; if ( write . isError ( ) ) { os :: close ( efd ) ; os :: close ( cfd . get ( ) ) ; return Try < int > :: error ( write . error ( ) ) ; } os :: close ( cfd . get ( ) ) ; return efd ; }
In cgroups, there is mechanism which allows to get notifications about
changing status of a cgroup.
In cgroups there is mechanism which allows to get notifications about changing status of a cgroup .
// Open the control file. // Write the event control file (cgroup.event_control).