leil-io / saunafs

SaunaFS is a free-and open source, distributed POSIX file system inspired by Google File System.
https://saunafs.com
GNU General Public License v3.0
58 stars 5 forks source link

Unhandled permission denied exception in plugin-manager.cc #220

Open uristdwarf opened 2 days ago

uristdwarf commented 2 days ago

When the chunkserver plugin is not installed (as is the default in CMake right now), it will try to load the plugin from the build directory, which may not be available (could be either permissions or it could not exist, very common when transitioning from a build environment), this causes a exception which is handled by initialize, which then causes the program exits. This is undesired as chunkserver can work without a plugin.

Reproduce:

  1. Build and install from directory where saunafs (or whatever user is running chunkserver) cannot access the build files.
  2. Run chunkserver

Potential fix:

diff --git a/src/chunkserver/chunkserver-common/plugin_manager.cc b/src/chunkserver/chunkserver-common/plugin_manager.cc
index 30fa071a..69cf5568 100644
--- a/src/chunkserver/chunkserver-common/plugin_manager.cc
+++ b/src/chunkserver/chunkserver-common/plugin_manager.cc
@@ -19,19 +19,27 @@
 #include "common/platform.h"

 #include "chunkserver-common/plugin_manager.h"
+#include <boost/filesystem/exception.hpp>

 #include "chunkserver-common/disk_plugin.h"
 #include "slogger/slogger.h"

 bool PluginManager::loadPlugins(const std::string &directory) {
-   if (!boost::filesystem::is_directory(directory) ||
-       boost::filesystem::is_empty(directory)) {
-       // It is normal to not have any plugins in many scenarios
-       safs_pretty_syslog(
-           LOG_NOTICE,
-           "PluginManager: Directory %s does not exist or is empty",
-           directory.c_str());
-       return false;
+   try {
+       if (!boost::filesystem::is_directory(directory) ||
+           boost::filesystem::is_empty(directory)) {
+           // It is normal to not have any plugins in many scenarios
+           safs_pretty_syslog(
+               LOG_NOTICE,
+               "PluginManager: Directory %s does not exist or is empty",
+               directory.c_str());
+           return false;
+       }
+   } catch (boost::filesystem::filesystem_error &e) {
+           safs::log_info(
+               "PluginManager: Directory {} cannot not be checked: {}",
+               directory.c_str(), e.what());
+           return false;
    }

    boost::filesystem::path dir(directory);

Other idea is to include the chunkserver plugin by default when installing

uristdwarf commented 2 days ago

Thoughts @lgsilva3087?