1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-12 05:26:02 +01:00

Clean up cgroup handling in getMaxCPU()

Also, don't assume in LocalDerivationGoal that cgroups are mounted on
/sys/fs/cgroup.
This commit is contained in:
Eelco Dolstra 2022-12-02 12:57:41 +01:00
parent 1211e59a03
commit 1e6a5d1ff6
4 changed files with 39 additions and 35 deletions

View file

@ -409,12 +409,16 @@ void LocalDerivationGoal::startBuilder()
#if __linux__
settings.requireExperimentalFeature(Xp::Cgroups);
auto cgroupFS = getCgroupFS();
if (!cgroupFS)
throw Error("cannot determine the cgroups file system");
auto ourCgroups = getCgroups("/proc/self/cgroup");
auto ourCgroup = ourCgroups[""];
if (ourCgroup == "")
throw Error("cannot determine cgroup name from /proc/self/cgroup");
auto ourCgroupPath = canonPath("/sys/fs/cgroup/" + ourCgroup);
auto ourCgroupPath = canonPath(*cgroupFS + "/" + ourCgroup);
if (!pathExists(ourCgroupPath))
throw Error("expected cgroup directory '%s'", ourCgroupPath);