From: Elena Mamontova Date: Thu, 17 Mar 2016 07:39:43 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/stg-2.409' into ticket26 X-Git-Tag: 2.409~174^2~1^2~9 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/8c7e6453aff765245cc5c28f37543f13d92dbe74?hp=-c Merge remote-tracking branch 'origin/stg-2.409' into ticket26 --- 8c7e6453aff765245cc5c28f37543f13d92dbe74 diff --combined projects/stargazer/main.cpp index b878b39c,3c216977..34fc4bd0 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@@ -338,22 -338,8 +338,22 @@@ while (running switch (sig) { case SIGHUP: + { + SETTINGS_IMPL newSettings(settings); + if (newSettings.ReadSettings()) + { + STG_LOGGER & WriteServLog = GetStgLogger(); + + if (newSettings.GetLogFileName() != "") + WriteServLog.SetLogFileName(newSettings.GetLogFileName()); + + WriteServLog("ReadSettings error. %s", newSettings.GetStrError().c_str()); + return -1; + } + settings = newSettings; traffCnt.Reload(); - manager.reload(); + manager.reload(settings); + } break; case SIGTERM: running = false; @@@ -377,6 -363,8 +377,8 @@@ WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); + manager.stop(); + if (loop.Stop()) WriteServLog("Event loop not stopped."); diff --combined projects/stargazer/plugin_mgr.cpp index eec1d656,b87ab277..10911b97 --- a/projects/stargazer/plugin_mgr.cpp +++ b/projects/stargazer/plugin_mgr.cpp @@@ -60,12 -60,11 +60,12 @@@ PluginManager::PluginManager(const SETT for (size_t i = 0; i < modSettings.size(); i++) { std::string modulePath = basePath + "/mod_" + modSettings[i].moduleName + ".so"; + std::string moduleName = modSettings[i].moduleName; printfd(__FILE__, "Module: %s\n", modulePath.c_str()); try { m_modules.push_back( - new PLUGIN_RUNNER(modulePath, modSettings[i], admins, tariffs, + new PLUGIN_RUNNER(modulePath, moduleName, modSettings[i], admins, tariffs, users, services, corporations, traffcounter, store, settings) ); @@@ -98,45 -97,45 +98,52 @@@ PluginManager::~PluginManager() { - std::sort(m_modules.begin(), m_modules.end(), StopModCmp); - for (size_t i = 0; i < m_modules.size(); ++i) - { - PLUGIN & plugin = m_modules[i]->GetPlugin(); - if (m_modules[i]->Stop()) - { - m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - } - else - { - m_log("Module '%s' stopped successfully.", plugin.GetVersion().c_str()); - printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str()); - } - } + stop(); for (size_t i = 0; i < m_modules.size(); ++i) delete m_modules[i]; } -void PluginManager::reload() +void PluginManager::reload(const SETTINGS_IMPL& settings) { + const std::vector & modSettings(settings.GetModulesSettings()); for (size_t i = 0; i < m_modules.size(); ++i) { - PLUGIN & plugin = m_modules[i]->GetPlugin(); - if (m_modules[i]->Reload()) + for (size_t j = 0; j < modSettings.size(); j++) { - m_log("Error reloading module '%s': '%s'", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - printfd(__FILE__, "Error reloading module '%s': '%s'\n", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); + if (modSettings[j].moduleName == m_modules[i]->GetName()) + { + PLUGIN & plugin = m_modules[i]->GetPlugin(); + if (m_modules[i]->Reload(modSettings[j])) + { + m_log("Error reloading module '%s': '%s'", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + printfd(__FILE__, "Error reloading module '%s': '%s'\n", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + } + } } } } + + void PluginManager::stop() + { + std::sort(m_modules.begin(), m_modules.end(), StopModCmp); + for (size_t i = 0; i < m_modules.size(); ++i) + { + if (!m_modules[i]->IsRunning()) + continue; + PLUGIN & plugin = m_modules[i]->GetPlugin(); + if (m_modules[i]->Stop()) + { + m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + } + else + { + m_log("Module '%s' stopped successfully.", plugin.GetVersion().c_str()); + printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str()); + } + } + } diff --combined projects/stargazer/plugin_mgr.h index 0330f4e8,c9ec8dff..a37052d5 --- a/projects/stargazer/plugin_mgr.h +++ b/projects/stargazer/plugin_mgr.h @@@ -48,7 -48,8 +48,8 @@@ class PluginManage USERS_IMPL& users, TRAFFCOUNTER_IMPL& traffcounter); ~PluginManager(); - void reload(); + void reload(const SETTINGS_IMPL& settings); + void stop(); private: std::vector m_modules; diff --combined projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 4456c372,8be662e9..6b34618f --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@@ -86,7 -86,7 +86,7 @@@ std::vector::const_iterato /////////////////////////// pv.param = "Port"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@@ -102,7 -102,7 +102,7 @@@ port = static_cast(p) /////////////////////////// pv.param = "UserDelay"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'UserDelay\' not found."; printfd(__FILE__, "Parameter 'UserDelay' not found\n"); @@@ -118,7 -118,7 +118,7 @@@ if (ParseIntInRange(pvi->value[0], 5, 6 /////////////////////////// pv.param = "UserTimeout"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'UserTimeout\' not found."; printfd(__FILE__, "Parameter 'UserTimeout' not found\n"); @@@ -134,7 -134,7 +134,7 @@@ if (ParseIntInRange(pvi->value[0], 15, /////////////////////////// pv.param = "LogProtocolErrors"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) logProtocolErrors = false; else if (ParseYesNo(pvi->value[0], &logProtocolErrors)) { @@@ -147,7 -147,7 +147,7 @@@ std::string freeMbType int n = 0; pv.param = "FreeMb"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'FreeMb\' not found."; printfd(__FILE__, "Parameter 'FreeMb' not found\n"); @@@ -188,15 -188,13 +188,13 @@@ return 0 #ifdef IA_PHASE_DEBUG IA_PHASE::IA_PHASE() : phase(1), - phaseTime(), flog(NULL) { gettimeofday(&phaseTime, NULL); } #else IA_PHASE::IA_PHASE() - : phase(1), - phaseTime() + : phase(1) { gettimeofday(&phaseTime, NULL); } @@@ -526,23 -524,6 +524,23 @@@ if (ret return ret; } //----------------------------------------------------------------------------- +int AUTH_IA::Reload(const MODULE_SETTINGS & ms) +{ +AUTH_IA_SETTINGS newIaSettings; +if (newIaSettings.ParseSettings(ms)) + { + STG_LOGGER & WriteServLog = GetStgLogger(); + printfd(__FILE__, "AUTH_IA::Reload() - Failed to reload InetAccess.\n"); + WriteServLog("AUTH_IA: Cannot reload InetAccess. Errors found."); + return -1; + } + +STG_LOGGER & WriteServLog = GetStgLogger(); +printfd(__FILE__, "AUTH_IA::Reload() - Reloaded InetAccess successfully.\n"); +WriteServLog("AUTH_IA: Reloaded InetAccess successfully."); +return 0; +} +//----------------------------------------------------------------------------- int AUTH_IA::PrepareNet() { struct sockaddr_in listenAddr; diff --combined projects/stargazer/plugins/other/rscript/rscript.cpp index 27c419b8,928629ad..74bf87a1 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@@ -73,12 -73,7 +73,7 @@@ return rsc.GetPlugin() //----------------------------------------------------------------------------- RS::SETTINGS::SETTINGS() : sendPeriod(0), - port(0), - errorStr(), - netRouters(), - userParams(), - password(), - subnetFile() + port(0) { } //----------------------------------------------------------------------------- @@@ -91,7 -86,7 +86,7 @@@ netRouters.clear() /////////////////////////// pv.param = "Port"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@@ -107,7 -102,7 +102,7 @@@ port = static_cast(p) /////////////////////////// pv.param = "SendPeriod"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'SendPeriod\' not found."; printfd(__FILE__, "Parameter 'SendPeriod' not found\n"); @@@ -123,7 -118,7 +118,7 @@@ if (ParseIntInRange(pvi->value[0], 5, 6 /////////////////////////// pv.param = "UserParams"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'UserParams\' not found."; printfd(__FILE__, "Parameter 'UserParams' not found\n"); @@@ -133,7 -128,7 +128,7 @@@ userParams = pvi->value /////////////////////////// pv.param = "Password"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Password\' not found."; printfd(__FILE__, "Parameter 'Password' not found\n"); @@@ -143,7 -138,7 +138,7 @@@ password = pvi->value[0] /////////////////////////// pv.param = "SubnetFile"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'SubnetFile\' not found."; printfd(__FILE__, "Parameter 'SubnetFile' not found\n"); @@@ -301,7 -296,7 +296,7 @@@ if (isRunning return 0; } //----------------------------------------------------------------------------- -int REMOTE_SCRIPT::Reload() +int REMOTE_SCRIPT::Reload(const MODULE_SETTINGS & ms) { NRMapParser nrMapParser; diff --combined projects/stargazer/plugins/other/smux/smux.cpp index d1af2dbc,9ff739cb..5a20d495 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@@ -24,9 -24,6 +24,6 @@@ namespac { PLUGIN_CREATOR smc; - bool SPrefixLess(const Sensors::value_type & a, - const Sensors::value_type & b); - bool SPrefixLess(const Sensors::value_type & a, const Sensors::value_type & b) { @@@ -57,7 -54,7 +54,7 @@@ int p pv.param = "Port"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@@ -73,7 -70,7 +70,7 @@@ port = static_cast(p) pv.param = "Password"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Password\' not found."; printfd(__FILE__, "Parameter 'Password' not found\n"); @@@ -86,7 -83,7 +83,7 @@@ els pv.param = "Server"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Server\' not found."; printfd(__FILE__, "Parameter 'Server' not found\n"); @@@ -272,7 -269,7 +269,7 @@@ printfd(__FILE__, "SMUX::Stop() - After return 0; } -int SMUX::Reload() +int SMUX::Reload(const MODULE_SETTINGS & ms) { if (Stop()) return -1;