Better fault tolerance in numericFolderItems
Summary:
Currently `numericFolderItems` can throw an exception even in case if it's coming from `stroul` which should be ignored.
Besides, returning an empty set if `readdir` has never succeeded at least once is a better option than throwing.
@@ -78,9 +78,8 @@ static std::unordered_set<uint32_t> numericFolderItems(const char* folder) {
}
items.emplace(item);
}
- if (errno != 0 || closedir(dir) != 0) {
- throw std::system_error(
- errno, std::system_category(), "readdir or closedir");
+ if (closedir(dir) != 0) {
+ throw std::system_error(errno, std::system_category(), "closedir");
}
return items;
}
@@ -579,10 +578,15 @@ VmStatFile::VmStatFile(std::string path)
// The order corresponds to the order in /proc/vmstat generated by the
// Linux kernel
- {
- {"nr_free_pages", sizeof("nr_free_pages") - 1, kNotSet, &VmStatInfo::nrFreePages},
+ {{"nr_free_pages",
+ sizeof("nr_free_pages") - 1,
+ kNotSet,
+ &VmStatInfo::nrFreePages},
{"nr_dirty", sizeof("nr_dirty") - 1, kNotSet, &VmStatInfo::nrDirty},
- {"nr_writeback", sizeof("nr_writeback") - 1, kNotSet, &VmStatInfo::nrWriteback},
+ {"nr_writeback",
+ sizeof("nr_writeback") - 1,
+ kNotSet,
+ &VmStatInfo::nrWriteback},
{"pgpgin", sizeof("pgpgin") - 1, kNotSet, &VmStatInfo::pgPgIn},
{"pgpgout", sizeof("pgpgout") - 1, kNotSet, &VmStatInfo::pgPgOut},
{"pgmajfault",
