DevinLeamy commented on code in PR #549:
URL: https://github.com/apache/mesos/pull/549#discussion_r1553739387


##########
src/linux/cgroups2.cpp:
##########
@@ -306,6 +308,45 @@ bool exists(const string& cgroup)
 }
 
 
+Try<set<string>> get(const string& cgroup)
+{
+  const string& path = cgroups2::path(cgroup);
+  char* paths[] = {const_cast<char*>(path.c_str()), nullptr};
+
+  FTS* tree = fts_open(paths, FTS_NOCHDIR, nullptr);
+  if (tree == nullptr) {
+    return ErrnoError("Failed to start traversing filesystem");
+  }
+
+  FTSENT* node;
+  set<string> cgroups;
+  while ((node = fts_read(tree)) != nullptr) {
+    // Use post-order walk here. fts_level is the depth of the traversal,
+    // numbered from -1 to N, where the file/dir was found. The traversal root
+    // itself is numbered 0. fts_info includes flags for the current node.
+    // FTS_DP indicates a directory being visited in postorder.
+    if (node->fts_level > 0 && node->fts_info & FTS_DP) {
+      string _cgroup = strings::trim(
+          node->fts_path + MOUNT_POINT.length(), "/");
+      cgroups.insert(_cgroup);
+    }
+  }
+
+  if (errno != 0) {
+    Error error =
+      ErrnoError("Failed to read a node while traversing the filesystem");
+    fts_close(tree);
+    return error;
+  }
+
+  if (fts_close(tree) != 0) {
+    return ErrnoError("Failed to stop traversing file system");
+  }
+
+  return cgroups;
+}

Review Comment:
   `cgroups::get`: 
https://github.com/apache/mesos/blob/b23908fa9c520a941111bf4c56ceee64d14331f1/src/linux/cgroups.cpp#L770



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to