diff options
author | aristocratos <gnmjpl@gmail.com> | 2023-12-12 22:55:48 +0100 |
---|---|---|
committer | aristocratos <gnmjpl@gmail.com> | 2023-12-12 22:55:48 +0100 |
commit | e770cccaf82cb75fe1e61c227284929e5a4acde1 (patch) | |
tree | a736e40675fa32dc714d3abf5e945a9d1f5953f8 | |
parent | 6282f36f8fe2fc1fa95a5858c044fbc6c7d965cf (diff) |
Added try->catch for get_zfs_stat_file() to avoid fs error
-rw-r--r-- | src/linux/btop_collect.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index ab4574f..a9bdc50 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -1936,29 +1936,32 @@ namespace Mem { } // looking through all files that start with 'objset' to find the one containing `device_name` object stats - for (const auto& file: fs::directory_iterator(zfs_pool_stat_path)) { - filename = file.path().filename(); - if (filename.starts_with("objset")) { - filestream.open(file.path()); - if (filestream.good()) { - // skip first two lines - for (int i = 0; i < 2; i++) filestream.ignore(numeric_limits<streamsize>::max(), '\n'); - // skip characters until '7' is reached, indicating data type 7, next value will be object name - filestream.ignore(numeric_limits<streamsize>::max(), '7'); - filestream >> name_compare; - if (name_compare == device_name) { - filestream.close(); - if (access(file.path().c_str(), R_OK) == 0) { - return file.path(); - } else { - Logger::debug("Can't access file: " + file.path().string()); - return ""; + try { + for (const auto& file: fs::directory_iterator(zfs_pool_stat_path)) { + filename = file.path().filename(); + if (filename.starts_with("objset")) { + filestream.open(file.path()); + if (filestream.good()) { + // skip first two lines + for (int i = 0; i < 2; i++) filestream.ignore(numeric_limits<streamsize>::max(), '\n'); + // skip characters until '7' is reached, indicating data type 7, next value will be object name + filestream.ignore(numeric_limits<streamsize>::max(), '7'); + filestream >> name_compare; + if (name_compare == device_name) { + filestream.close(); + if (access(file.path().c_str(), R_OK) == 0) { + return file.path(); + } else { + Logger::debug("Can't access file: " + file.path().string()); + return ""; + } } } + filestream.close(); } - filestream.close(); } } + catch (fs::filesystem_error& e) {} Logger::debug("Could not read directory: " + zfs_pool_stat_path.string()); return ""; |