| 60 | } |
| 61 | |
| 62 | std::optional<std::string> getCgroupsV2PathContainingFile([[maybe_unused]] std::string_view file_name) |
| 63 | { |
| 64 | #if defined(OS_LINUX) |
| 65 | if (!cgroupsV2Enabled()) |
| 66 | return {}; |
| 67 | |
| 68 | fs::path current_cgroup = cgroupV2PathOfProcess(); |
| 69 | if (current_cgroup.empty()) |
| 70 | return {}; |
| 71 | |
| 72 | /// Return the bottom-most nested file. If there is no such file at the current |
| 73 | /// level, try again at the parent level as settings are inherited. |
| 74 | while (current_cgroup != default_cgroups_mount.parent_path()) |
| 75 | { |
| 76 | const auto path = current_cgroup / file_name; |
| 77 | if (fs::exists(path)) |
| 78 | return {current_cgroup}; |
| 79 | current_cgroup = current_cgroup.parent_path(); |
| 80 | } |
| 81 | return {}; |
| 82 | #else |
| 83 | return {}; |
| 84 | #endif |
| 85 | } |
no test coverage detected