diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-05-16 21:21:41 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-07-06 13:50:33 +0200 |
commit | 570c443f560e015cf02e4f96102eaaa0e6853562 (patch) | |
tree | 95c1faf2560108719c071daa0ce0e74f3c01cc43 /src/libstore/cgroup.cc | |
parent | 7bdcf43b401eba6aee29a359c5bce1f9cc01ce52 (diff) |
Simplify cgroup creation
Diffstat (limited to 'src/libstore/cgroup.cc')
-rw-r--r-- | src/libstore/cgroup.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libstore/cgroup.cc b/src/libstore/cgroup.cc index 8cd682e68..887facdca 100644 --- a/src/libstore/cgroup.cc +++ b/src/libstore/cgroup.cc @@ -9,6 +9,23 @@ namespace nix { +std::map<std::string, std::string> getCgroups(const Path & cgroupFile) +{ + std::map<std::string, std::string> cgroups; + + for (auto & line : tokenizeString<std::vector<std::string>>(readFile(cgroupFile), "\n")) { + static std::regex regex("([0-9]+):([^:]*):(.*)"); + std::smatch match; + if (!std::regex_match(line, match, regex)) + throw Error("invalid line '%s' in '%s'", line, cgroupFile); + + std::string name = hasPrefix(match[2], "name=") ? std::string(match[2], 5) : match[2]; + cgroups.insert_or_assign(name, match[3]); + } + + return cgroups; +} + void destroyCgroup(const Path & cgroup) { for (auto & entry : readDirectory(cgroup)) { |