From e9453e62e4ce810e82826122a036802b00cf2474 Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Wed, 10 Jan 2024 11:17:37 +0200 Subject: [PATCH] fix: ignore unexpected contents for /sys/fs/cgroup/cpu.max (#2394) Fixes #2391 Signed-off-by: Roman Gershman --- src/server/dfly_main.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/server/dfly_main.cc b/src/server/dfly_main.cc index e89a99fd0..734ec1569 100644 --- a/src/server/dfly_main.cc +++ b/src/server/dfly_main.cc @@ -475,22 +475,23 @@ bool UpdateResourceLimitsIfInsideContainer(io::MemInfoData* mdata, size_t* max_t if (auto cpu = ReadFileToString(StrCat(path, "/cpu.max")); cpu.has_value()) { vector res = absl::StrSplit(*cpu, ' '); - CHECK_EQ(res.size(), 2u); + // Some linux distributions do not have anything there. + if (res.size() == 2u) { + if (res[0] == "max") + *output = 0u; + else { + CHECK(absl::SimpleAtod(res[0], &count)) + << "Failed in parsing cgroupv2 cpu count, path = " << path << " (read: " << *cpu + << ")"; + CHECK(absl::SimpleAtod(res[1], ×hare)) + << "Failed in parsing cgroupv2 cpu timeshare, path = " << path << " (read: " << *cpu + << ")"; - if (res[0] == "max") - *output = 0u; - else { - CHECK(absl::SimpleAtod(res[0], &count)) - << "Failed in parsing cgroupv2 cpu count, path = " << path << " (read: " << *cpu << ")"; - CHECK(absl::SimpleAtod(res[1], ×hare)) - << "Failed in parsing cgroupv2 cpu timeshare, path = " << path << " (read: " << *cpu - << ")"; + *output = static_cast(ceil(count / timeshare)); + } - *output = static_cast(ceil(count / timeshare)); + read_something = true; } - - read_something = true; - } else if (auto quota = ReadFileToString(StrCat(path, "/cpu.cfs_quota_us")); quota.has_value()) { auto period = ReadFileToString(StrCat(path, "/cpu.cfs_period_us"));