fix: ignore unexpected contents for /sys/fs/cgroup/cpu.max (#2394)

Fixes #2391

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-01-10 11:17:37 +02:00 committed by GitHub
parent b8af49cfe5
commit e9453e62e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -475,13 +475,14 @@ bool UpdateResourceLimitsIfInsideContainer(io::MemInfoData* mdata, size_t* max_t
if (auto cpu = ReadFileToString(StrCat(path, "/cpu.max")); cpu.has_value()) {
vector<string_view> 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 << ")";
<< "Failed in parsing cgroupv2 cpu count, path = " << path << " (read: " << *cpu
<< ")";
CHECK(absl::SimpleAtod(res[1], &timeshare))
<< "Failed in parsing cgroupv2 cpu timeshare, path = " << path << " (read: " << *cpu
<< ")";
@ -490,7 +491,7 @@ bool UpdateResourceLimitsIfInsideContainer(io::MemInfoData* mdata, size_t* max_t
}
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"));