fru-device:use noexcept std filesystem call
Update calls to use noexcept overload for is_symlink() and
std::filesystem::directory_iterator::directory_iterator in fru-device
This fixes service crash due to uncaught exception.
Tested:
Same FRU device are discovered on a platform with the code change.
Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Change-Id: I452e11d7713fdf09df47186ba6259ef2c6340019
diff --git a/src/fru_device.cpp b/src/fru_device.cpp
index 4afefca..2045b4e 100644
--- a/src/fru_device.cpp
+++ b/src/fru_device.cpp
@@ -164,8 +164,12 @@
static bool isMuxBus(size_t bus)
{
- return is_symlink(std::filesystem::path(
- "/sys/bus/i2c/devices/i2c-" + std::to_string(bus) + "/mux_device"));
+ auto ec = std::error_code();
+ auto isSymlink =
+ is_symlink(std::filesystem::path("/sys/bus/i2c/devices/i2c-" +
+ std::to_string(bus) + "/mux_device"),
+ ec);
+ return (!ec && isSymlink);
}
static void makeProbeInterface(size_t bus, size_t address,
@@ -308,8 +312,14 @@
// For each file listed under the i2c device
// NOTE: This should be faster than just checking for each possible address
// path.
- for (const auto& p : fs::directory_iterator(path))
+ auto ec = std::error_code();
+ for (const auto& p : fs::directory_iterator(path, ec))
{
+ if (ec)
+ {
+ std::cerr << "directory_iterator err " << ec.message() << "\n";
+ break;
+ }
const std::string node = p.path().string();
std::smatch m;
bool found = std::regex_match(node, m,