diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-01-04 22:22:36 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-01-04 22:22:36 +0000 |
commit | 0334fad13f0c7566fbb9f8a0829b9c95d861ee57 (patch) | |
tree | f34f7c60f774cf81580d62e44e0ff902eec344f2 | |
parent | Scrap the precompiled headers (diff) | |
download | netfs-1.1.5.tar.bz2 netfs-1.1.5.tar.xz netfs-1.1.5.zip |
Improve error handling around unavailable daemonnetfs-1.1.5
-rw-r--r-- | netfs/fuse/fuseApp.cpp | 58 | ||||
-rw-r--r-- | netfs/unittests/testEdgeCases.cpp | 41 |
2 files changed, 85 insertions, 14 deletions
diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index d37d40c..4766360 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -23,16 +23,36 @@ NetFS::FuseApp::FuseApp(const Ice::StringSeq & a) : NetFS::FuseApp::~FuseApp() { for (const OpenDirs::value_type & of : openDirs) { - of.second->remote->close(); + try { + of.second->remote->close(); + } + catch (...) { + // Can't do anything useful here + } } for (const OpenFiles::value_type & of : openFiles) { - of.second->remote->close(); + try { + of.second->remote->close(); + } + catch (...) { + // Can't do anything useful here + } } if (volume) { - volume->disconnect(); + try { + volume->disconnect(); + } + catch (...) { + // Can't do anything useful here + } } if (session) { - session->destroy(); + try { + session->destroy(); + } + catch (...) { + // Can't do anything useful here + } } if (ic) { ic->destroy(); @@ -183,18 +203,28 @@ NetFS::FuseApp::onError(const std::exception & e) throw() { if (dynamic_cast<const Ice::SocketException *>(&e) || dynamic_cast<const Ice::TimeoutException *>(&e)) { log(LOG_ERR, e.what()); - verifyConnection(); - connectSession(); - connectToService(); - connectToVolume(); - connectHandles(); - return 0; + try { + verifyConnection(); + connectSession(); + connectToService(); + connectToVolume(); + connectHandles(); + return 0; + } + catch (...) { + return -ENOSYS; + } } if (dynamic_cast<const Ice::RequestFailedException *>(&e)) { - volume = NULL; - connectToVolume(); - connectHandles(); - return 0; + try { + volume = NULL; + connectToVolume(); + connectHandles(); + return 0; + } + catch (...) { + return -ENOSYS; + } } if (dynamic_cast<const NetFS::AuthError *>(&e)) { return -EPERM; diff --git a/netfs/unittests/testEdgeCases.cpp b/netfs/unittests/testEdgeCases.cpp index b1b7a44..7bf543c 100644 --- a/netfs/unittests/testEdgeCases.cpp +++ b/netfs/unittests/testEdgeCases.cpp @@ -58,3 +58,44 @@ BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) BOOST_REQUIRE_EQUAL(0, fuse.fuse->release(fileName, &fh)); } +BOOST_AUTO_TEST_CASE( noDaemonAtStartUp ) +{ + FuseMockHost fuse(testEndpoint, { + (RootDir / "defaultFuse.xml:testvol").string(), + (RootDir / "test").string() + }); + + struct statvfs s; + BOOST_REQUIRE_EQUAL(-ENOSYS, fuse.fuse->statfs("/", &s)); + MockDaemonHost daemon(testEndpoint, { + "--NetFSD.ConfigPath=" + (RootDir / "defaultDaemon.xml").string() + }); + + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); +} + +BOOST_AUTO_TEST_CASE ( daemonUnavailableAfterUse ) +{ + FuseMockHost fuse(testEndpoint, { + (RootDir / "defaultFuse.xml:testvol").string(), + (RootDir / "test").string() + }); + struct statvfs s; + { + MockDaemonHost daemon(testEndpoint, { + "--NetFSD.ConfigPath=" + (RootDir / "defaultDaemon.xml").string() + }); + + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); + } + BOOST_REQUIRE_EQUAL(-ENOSYS, fuse.fuse->statfs("/", &s)); + { + MockDaemonHost daemon(testEndpoint, { + "--NetFSD.ConfigPath=" + (RootDir / "defaultDaemon.xml").string() + }); + + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); + } + BOOST_REQUIRE_EQUAL(-ENOSYS, fuse.fuse->statfs("/", &s)); +} + |