Fix unhandled exception when FUSE disabled
When running on kernel without FUSE, fs::directory_iterator
throws exception since /sys/fs/fuse/connections is missing.
This patch uses non-throwing fs::directory_iterator
and adds explicit error check.
Test: vold doesn't fail with FUSE disabled
Signed-off-by: Oleg Lyovin <ovlevin@sberdevices.ru>
Change-Id: I51b68363edf75033fcec3ce5623f419d5a68c991
diff --git a/Utils.cpp b/Utils.cpp
index 9e77a9e..23e8867 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -1448,7 +1448,10 @@
status_t AbortFuseConnections() {
namespace fs = std::filesystem;
- for (const auto& itEntry : fs::directory_iterator("/sys/fs/fuse/connections")) {
+ static constexpr const char* kFuseConnections = "/sys/fs/fuse/connections";
+
+ std::error_code ec;
+ for (const auto& itEntry : fs::directory_iterator(kFuseConnections, ec)) {
std::string fsPath = itEntry.path().string() + "/filesystem";
std::string fs;
@@ -1468,6 +1471,11 @@
}
}
+ if (ec) {
+ LOG(WARNING) << "Failed to iterate through " << kFuseConnections << ": " << ec.message();
+ return -ec.value();
+ }
+
return OK;
}