This commit is contained in:
Igor Solodovnikov 2026-05-25 05:00:37 +08:00 committed by GitHub
commit d86ba4fc21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -496,6 +496,8 @@ public:
if (f != nullptr) {
if (fgets(fstr, 1023, f) != nullptr)
fstr[strlen(fstr) < 1 ? 0 : strlen(fstr) - 1] = '\0';
else
fstr[0] = '\0';
fclose(f);
}
return fstr;

View File

@ -43,6 +43,8 @@ std::string parseLineFromFile(const char* fname) {
if (f != nullptr) {
if (fgets(fstr, 1023, f) != nullptr)
fstr[strlen(fstr) < 1 ? 0 : strlen(fstr) - 1] = '\0';
else
fstr[0] = '\0';
fclose(f);
}
@ -69,7 +71,8 @@ unsigned long long getMemorySizeLimitInBytes() {
unsigned long long groupMemBytes = 0;
std::string groupLimit = parseLineFromFile(file);
if (!groupLimit.empty() ) {
// The "max" value in cgroups v2 means no limit.
if (!groupLimit.empty() && groupLimit != "max") {
return std::min(systemMemBytes, (unsigned long long)atoll(groupLimit.c_str()));
}
}