X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/55a204e46261850f1a26ebafc45fb3ba6f0604c6..a8f9a1d87d5c6847b368984454c09c597757aba2:/projects/stargazer/plugin_runner.cpp diff --git a/projects/stargazer/plugin_runner.cpp b/projects/stargazer/plugin_runner.cpp index bcf68bee..e57a421e 100644 --- a/projects/stargazer/plugin_runner.cpp +++ b/projects/stargazer/plugin_runner.cpp @@ -28,6 +28,7 @@ //----------------------------------------------------------------------------- PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & fileName, + const std::string & name, const MODULE_SETTINGS & ms, ADMINS & admins, TARIFFS & tariffs, @@ -38,6 +39,7 @@ PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & fileName, STORE & store, const SETTINGS & settings) : pluginFileName(fileName), + pluginName(name), libHandle(NULL), m_plugin(Load(ms, admins, tariffs, users, services, corporations, traffcounter, store, settings)) @@ -67,9 +69,9 @@ errorStr = m_plugin.GetStrError(); return res; } //----------------------------------------------------------------------------- -int PLUGIN_RUNNER::Reload() +int PLUGIN_RUNNER::Reload(const MODULE_SETTINGS & ms) { -int res = m_plugin.Reload(); +int res = m_plugin.Reload(ms); errorStr = m_plugin.GetStrError(); return res; } @@ -86,35 +88,45 @@ PLUGIN & PLUGIN_RUNNER::Load(const MODULE_SETTINGS & ms, { if (pluginFileName.empty()) { - errorStr = "Empty plugin file name."; - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + const std::string msg = "Empty plugin file name."; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); + } + +if (access(pluginFileName.c_str(), R_OK)) + { + const std::string msg = "Plugin file '" + pluginFileName + "' is missing or inaccessible."; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } libHandle = dlopen(pluginFileName.c_str(), RTLD_NOW); if (!libHandle) { - errorStr = "Error loading plugin '" + pluginFileName + "': '" + dlerror() + "'"; - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + std::string msg = "Error loading plugin '" + pluginFileName + "'"; + const char* error = dlerror(); + if (error) + msg = msg + ": '" + error + "'"; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } PLUGIN * (*GetPlugin)(); GetPlugin = (PLUGIN * (*)())dlsym(libHandle, "GetPlugin"); if (!GetPlugin) { - errorStr = "Plugin '" + pluginFileName + "' does not have GetPlugin() function. " + dlerror(); - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + const std::string msg = "Plugin '" + pluginFileName + "' does not have GetPlugin() function. "; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } PLUGIN * plugin = GetPlugin(); if (!plugin) { - errorStr = "Failed to create an instance of plugin '" + pluginFileName + "'."; - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + const std::string msg = "Failed to create an instance of plugin '" + pluginFileName + "'."; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } plugin->SetSettings(ms); @@ -129,9 +141,9 @@ plugin->SetStgSettings(&settings); if (plugin->ParseSettings()) { - errorStr = "Plugin '" + pluginFileName + "' is unable to parse settings. " + plugin->GetStrError(); - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + const std::string msg = "Plugin '" + pluginFileName + "' is unable to parse settings. " + plugin->GetStrError(); + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } return *plugin;