MCPcopy Create free account
hub / github.com/apache/mesos / registerNotifier

Function registerNotifier

src/linux/cgroups.cpp:1030–1072  ·  view source on GitHub ↗

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 ev

Source from the content-addressed store, hash-verified

1028// @return The eventfd if the operation succeeds.
1029// Error if the operation fails.
1030static Try<int> registerNotifier(
1031 const string& hierarchy,
1032 const string& cgroup,
1033 const string& control,
1034 const Option<string>& args = None())
1035{
1036 int efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
1037 if (efd < 0) {
1038 return ErrnoError("Failed to create an eventfd");
1039 }
1040
1041 // Open the control file.
1042 string path = path::join(hierarchy, cgroup, control);
1043 Try<int> cfd = os::open(path, O_RDWR | O_CLOEXEC);
1044 if (cfd.isError()) {
1045 os::close(efd);
1046 return Error("Failed to open '" + path + "': " + cfd.error());
1047 }
1048
1049 // Write the event control file (cgroup.event_control).
1050 ostringstream out;
1051 out << dec << efd << " " << cfd.get();
1052 if (args.isSome()) {
1053 out << " " << args.get();
1054 }
1055
1056 Try<Nothing> write = cgroups::write(
1057 hierarchy,
1058 cgroup,
1059 "cgroup.event_control",
1060 out.str());
1061
1062 if (write.isError()) {
1063 os::close(efd);
1064 os::close(cfd.get());
1065 return Error(
1066 "Failed to write control 'cgroup.event_control': " + write.error());
1067 }
1068
1069 os::close(cfd.get());
1070
1071 return efd;
1072}
1073
1074
1075// Unregister a notifier.

Callers 1

initializeMethod · 0.85

Calls 12

NoneClass · 0.85
eventfdFunction · 0.85
ErrnoErrorClass · 0.85
closeFunction · 0.70
writeFunction · 0.70
errorMethod · 0.65
joinFunction · 0.50
openFunction · 0.50
ErrorFunction · 0.50
isErrorMethod · 0.45
getMethod · 0.45
isSomeMethod · 0.45

Tested by

no test coverage detected