From: Maxim Mamontov Date: Sat, 20 Aug 2016 10:24:56 +0000 (+0300) Subject: Merge branch 'stg-2.409' into stg-2.409-radius X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/f3300c448f21eb61c08284f1e210bd7766da784e?hp=9e6bfec34d7980e5c0af100110721ffd09f46e29 Merge branch 'stg-2.409' into stg-2.409-radius --- diff --git a/include/stg/plugin.h b/include/stg/plugin.h index 114ffc8b..2deabcc3 100644 --- a/include/stg/plugin.h +++ b/include/stg/plugin.h @@ -59,7 +59,7 @@ public: virtual int Start() = 0; virtual int Stop() = 0; - virtual int Reload() = 0; + virtual int Reload(const MODULE_SETTINGS &) = 0; virtual bool IsRunning() = 0; virtual const std::string & GetStrError() const = 0; virtual std::string GetVersion() const = 0; diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 3c216977..702bfb86 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -266,6 +266,11 @@ for (size_t i = 0; i < settings.GetExecutersNum(); i++) PIDFile pidFile(settings.GetPIDFileName()); +struct sigaction sa; +memset(&sa, 0, sizeof(sa)); +sa.sa_handler = SIG_DFL; +sigaction(SIGHUP, &sa, NULL); // Apparently FreeBSD ignores SIGHUP by default when launched from rc.d at bot time. + sigset_t signalSet; sigfillset(&signalSet); pthread_sigmask(SIG_BLOCK, &signalSet, NULL); @@ -338,8 +343,16 @@ while (running) switch (sig) { case SIGHUP: + { + SETTINGS_IMPL newSettings(settings); + if (newSettings.ReadSettings()) + WriteServLog("ReadSettings error. %s", newSettings.GetStrError().c_str()); + else + settings = newSettings; + WriteServLog.SetLogFileName(settings.GetLogFileName()); traffCnt.Reload(); - manager.reload(); + manager.reload(settings); + } break; case SIGTERM: running = false; diff --git a/projects/stargazer/plugin_mgr.cpp b/projects/stargazer/plugin_mgr.cpp index b87ab277..85215c7b 100644 --- a/projects/stargazer/plugin_mgr.cpp +++ b/projects/stargazer/plugin_mgr.cpp @@ -59,12 +59,13 @@ PluginManager::PluginManager(const SETTINGS_IMPL& settings, const std::vector & modSettings(settings.GetModulesSettings()); for (size_t i = 0; i < modSettings.size(); i++) { - std::string modulePath = basePath + "/mod_" + modSettings[i].moduleName + ".so"; + std::string moduleName = modSettings[i].moduleName; + std::string modulePath = basePath + "/mod_" + moduleName + ".so"; 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) ); @@ -102,17 +103,25 @@ PluginManager::~PluginManager() 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()); + } + break; + } } } } diff --git a/projects/stargazer/plugin_mgr.h b/projects/stargazer/plugin_mgr.h index c9ec8dff..a37052d5 100644 --- a/projects/stargazer/plugin_mgr.h +++ b/projects/stargazer/plugin_mgr.h @@ -48,7 +48,7 @@ class PluginManager USERS_IMPL& users, TRAFFCOUNTER_IMPL& traffcounter); ~PluginManager(); - void reload(); + void reload(const SETTINGS_IMPL& settings); void stop(); private: diff --git a/projects/stargazer/plugin_runner.cpp b/projects/stargazer/plugin_runner.cpp index eaf51058..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; } diff --git a/projects/stargazer/plugin_runner.h b/projects/stargazer/plugin_runner.h index 1402d2ef..2d0c22c4 100644 --- a/projects/stargazer/plugin_runner.h +++ b/projects/stargazer/plugin_runner.h @@ -46,6 +46,7 @@ public: }; PLUGIN_RUNNER(const std::string & pluginFileName, + const std::string & pluginName, const MODULE_SETTINGS & ms, ADMINS & admins, TARIFFS & tariffs, @@ -59,13 +60,14 @@ public: int Start(); int Stop(); - int Reload(); + int Reload(const MODULE_SETTINGS & ms); int Restart(); bool IsRunning() { return m_plugin.IsRunning(); } const std::string & GetStrError() const { return errorStr; } PLUGIN & GetPlugin() { return m_plugin; } const std::string & GetFileName() const { return pluginFileName; } + const std::string & GetName() const { return pluginName; } uint16_t GetStartPosition() const { return m_plugin.GetStartPosition(); } uint16_t GetStopPosition() const { return m_plugin.GetStopPosition(); } @@ -85,6 +87,7 @@ private: const SETTINGS & settings); std::string pluginFileName; + std::string pluginName; void * libHandle; PLUGIN & m_plugin; diff --git a/projects/stargazer/plugins/authorization/ao/ao.h b/projects/stargazer/plugins/authorization/ao/ao.h index d8b6dc88..9ed7ffcf 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.h +++ b/projects/stargazer/plugins/authorization/ao/ao.h @@ -89,7 +89,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS &) {} int ParseSettings() { return 0; } diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 8be662e9..99e0a091 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -524,6 +524,22 @@ if (ret) return ret; } //----------------------------------------------------------------------------- +int AUTH_IA::Reload(const MODULE_SETTINGS & ms) +{ +AUTH_IA_SETTINGS newIaSettings; +if (newIaSettings.ParseSettings(ms)) + { + printfd(__FILE__, "AUTH_IA::Reload() - Failed to reload InetAccess.\n"); + logger("AUTH_IA: Cannot reload InetAccess. Errors found."); + return -1; + } + +printfd(__FILE__, "AUTH_IA::Reload() - Reloaded InetAccess successfully.\n"); +logger("AUTH_IA: Reloaded InetAccess successfully."); +iaSettings = newIaSettings; +return 0; +} +//----------------------------------------------------------------------------- int AUTH_IA::PrepareNet() { struct sockaddr_in listenAddr; diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index 5e454124..2b527076 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -247,7 +247,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms); bool IsRunning() { return isRunningRunTimeouter || isRunningRun; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/authorization/stress/stress.h b/projects/stargazer/plugins/authorization/stress/stress.h index 83ab3231..6ead8f33 100644 --- a/projects/stargazer/plugins/authorization/stress/stress.h +++ b/projects/stargazer/plugins/authorization/stress/stress.h @@ -93,7 +93,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning(); void SetSettings(const MODULE_SETTINGS & s); int ParseSettings(); diff --git a/projects/stargazer/plugins/capture/cap_debug/debug_cap.h b/projects/stargazer/plugins/capture/cap_debug/debug_cap.h index 6bea457f..8b1ccb92 100644 --- a/projects/stargazer/plugins/capture/cap_debug/debug_cap.h +++ b/projects/stargazer/plugins/capture/cap_debug/debug_cap.h @@ -69,7 +69,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } int ParseSettings() { return 0; } bool IsRunning(); const std::string & GetStrError() const; diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h index bcb8b743..7d24403b 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h @@ -99,7 +99,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return runningTCP || runningUDP; } const std::string & GetStrError() const { return errorStr; } std::string GetVersion() const { return VERSION; } diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h index b34f832e..d8f4d6f8 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h @@ -51,7 +51,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h index 76785ed2..b9150b8d 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h @@ -98,7 +98,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h index 8dfb6c04..5bb938fe 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h @@ -52,7 +52,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } int ParseSettings() { return 0; } diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h index 39ed5766..b7f76b05 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h @@ -47,7 +47,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } int ParseSettings() { return 0; } diff --git a/projects/stargazer/plugins/capture/nfqueue/nfqueue.h b/projects/stargazer/plugins/capture/nfqueue/nfqueue.h index 87124784..27198073 100644 --- a/projects/stargazer/plugins/capture/nfqueue/nfqueue.h +++ b/projects/stargazer/plugins/capture/nfqueue/nfqueue.h @@ -51,7 +51,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h index 72a14f21..ce295818 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h @@ -70,7 +70,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return running && !stopped; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h index 287c3813..d1fbf24c 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h @@ -60,7 +60,7 @@ class STG_CONFIG : public PLUGIN int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/ping/ping.h b/projects/stargazer/plugins/other/ping/ping.h index 29e4974e..cfab1e55 100644 --- a/projects/stargazer/plugins/other/ping/ping.h +++ b/projects/stargazer/plugins/other/ping/ping.h @@ -112,7 +112,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning(); const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 742923f0..52da138e 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -56,7 +56,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return m_running; } const std::string& GetStrError() const { return m_error; } diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index 928629ad..4433dafd 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -296,7 +296,7 @@ if (isRunning) return 0; } //----------------------------------------------------------------------------- -int REMOTE_SCRIPT::Reload() +int REMOTE_SCRIPT::Reload(const MODULE_SETTINGS & /*ms*/) { NRMapParser nrMapParser; diff --git a/projects/stargazer/plugins/other/rscript/rscript.h b/projects/stargazer/plugins/other/rscript/rscript.h index e0412fb0..0de1ea2e 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.h +++ b/projects/stargazer/plugins/other/rscript/rscript.h @@ -185,7 +185,7 @@ public: int Start(); int Stop(); - int Reload(); + int Reload(const MODULE_SETTINGS & ms); bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index 9ff739cb..4586807c 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -269,7 +269,7 @@ printfd(__FILE__, "SMUX::Stop() - After\n"); return 0; } -int SMUX::Reload() +int SMUX::Reload(const MODULE_SETTINGS & /*ms*/) { if (Stop()) return -1; diff --git a/projects/stargazer/plugins/other/smux/smux.h b/projects/stargazer/plugins/other/smux/smux.h index e379ea7f..3b217eb7 100644 --- a/projects/stargazer/plugins/other/smux/smux.h +++ b/projects/stargazer/plugins/other/smux/smux.h @@ -116,7 +116,7 @@ public: int Start(); int Stop(); - int Reload(); + int Reload(const MODULE_SETTINGS & ms); bool IsRunning() { return running && !stopped; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index 67b4272f..8c728fdc 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -119,6 +119,111 @@ SETTINGS_IMPL::SETTINGS_IMPL(const std::string & cd) { } //----------------------------------------------------------------------------- +SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) + : SETTINGS(), + strError(), + modulesPath(rval.modulesPath), + dirName(rval.dirName), + confDir(rval.confDir), + scriptsDir(rval.scriptsDir), + rules(rval.rules), + logFile(rval.logFile), + pidFile(rval.pidFile), + monitorDir(rval.monitorDir), + monitoring(rval.monitoring), + detailStatWritePeriod(rval.detailStatWritePeriod), + statWritePeriod(rval.statWritePeriod), + stgExecMsgKey(rval.stgExecMsgKey), + executersNum(rval.executersNum), + fullFee(rval.fullFee), + dayFee(rval.dayFee), + dayResetTraff(rval.dayResetTraff), + spreadFee(rval.spreadFee), + freeMbAllowInet(rval.freeMbAllowInet), + dayFeeIsLastDay(rval.dayFeeIsLastDay), + writeFreeMbTraffCost(rval.writeFreeMbTraffCost), + showFeeInCash(rval.showFeeInCash), + messageTimeout(rval.messageTimeout), + feeChargeType(rval.feeChargeType), + reconnectOnTariffChange(rval.reconnectOnTariffChange), + modulesSettings(rval.modulesSettings), + storeModuleSettings(rval.storeModuleSettings), + logger(GetStgLogger()) +{ +} +//----------------------------------------------------------------------------- +SETTINGS_IMPL & SETTINGS_IMPL::operator=(const SETTINGS_IMPL & rhs) +{ + modulesPath = rhs.modulesPath; + dirName = rhs.dirName; + confDir = rhs.confDir; + scriptsDir = rhs.scriptsDir; + rules = rhs.rules; + logFile = rhs.logFile; + pidFile = rhs.pidFile; + monitorDir = rhs.monitorDir; + scriptParams = rhs.scriptParams; + monitoring = rhs.monitoring; + detailStatWritePeriod = rhs.detailStatWritePeriod; + statWritePeriod = rhs.statWritePeriod; + stgExecMsgKey = rhs.stgExecMsgKey; + executersNum = rhs.executersNum; + fullFee = rhs.fullFee; + dayFee = rhs.dayFee; + dayResetTraff = rhs.dayResetTraff; + spreadFee = rhs.spreadFee; + freeMbAllowInet = rhs.freeMbAllowInet; + dayFeeIsLastDay = rhs.dayFeeIsLastDay; + writeFreeMbTraffCost = rhs.writeFreeMbTraffCost; + showFeeInCash = rhs.showFeeInCash; + messageTimeout = rhs.messageTimeout; + feeChargeType = rhs.feeChargeType; + reconnectOnTariffChange = rhs.reconnectOnTariffChange; + + modulesSettings = rhs.modulesSettings; + storeModuleSettings = rhs.storeModuleSettings; + return *this; +} +//----------------------------------------------------------------------------- +int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector * params) +{ +const DOTCONFDocumentNode * childNode; +PARAM_VALUE pv; +const char * value; + +pv.param = node->getName(); + +if (node->getValue(1)) + { + strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'."; + return -1; + } + +value = node->getValue(0); + +if (!value) + { + strError = "Module name expected."; + return -1; + } + +childNode = node->getChildNode(); +while (childNode) + { + pv.param = childNode->getName(); + int i = 0; + while ((value = childNode->getValue(i++)) != NULL) + { + pv.value.push_back(value); + } + params->push_back(pv); + pv.value.clear(); + childNode = childNode->getNextNode(); + } + +return 0; +} +//----------------------------------------------------------------------------- void SETTINGS_IMPL::ErrorCallback(void * data, const char * buf) { printfd(__FILE__, "SETTINGS_IMPL::ErrorCallback() - %s\n", buf); diff --git a/projects/stargazer/settings_impl.h b/projects/stargazer/settings_impl.h index bab818c6..68fb9b0d 100644 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@ -25,6 +25,7 @@ #include #include "stg/settings.h" +#include "stg/common.h" #include "stg/module_settings.h" #include "stg/ref.h" @@ -42,7 +43,10 @@ class DOTCONFDocumentNode; class SETTINGS_IMPL : public SETTINGS { public: SETTINGS_IMPL(const std::string &); + SETTINGS_IMPL(const SETTINGS_IMPL & rhs); virtual ~SETTINGS_IMPL() {} + SETTINGS_IMPL & operator=(const SETTINGS_IMPL &); + int Reload() { return ReadSettings(); } int ReadSettings(); @@ -81,6 +85,8 @@ public: { return modulesSettings; } const std::vector & GetScriptParams() const { return scriptParams; } + int ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector * params); + private: static void ErrorCallback(void * data, const char * buf); diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 5d505307..d7bc8ea2 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -1494,13 +1494,18 @@ else if (!oldValue && newValue && user->IsInetable()) //----------------------------------------------------------------------------- void CHG_TARIFF_NOTIFIER::Notify(const std::string &, const std::string & newTariff) { +STG_LOCKER lock(&user->mutex); if (user->settings->GetReconnectOnTariffChange() && user->connected) user->Disconnect(false, "Change tariff"); user->tariff = user->tariffs->FindByName(newTariff); if (user->settings->GetReconnectOnTariffChange() && !user->authorizedBy.empty() && user->IsInetable()) + { + // This notifier gets called *before* changing the tariff, and in Connect we want to see new tariff name. + user->property.Conf().tariffName = newTariff; user->Connect(false); + } } //----------------------------------------------------------------------------- void CHG_CASH_NOTIFIER::Notify(const double & oldCash, const double & newCash) diff --git a/stglibs/logger.lib/include/stg/logger.h b/stglibs/logger.lib/include/stg/logger.h index 115d1fb3..e8d625a0 100644 --- a/stglibs/logger.lib/include/stg/logger.h +++ b/stglibs/logger.lib/include/stg/logger.h @@ -44,18 +44,19 @@ private: mutable pthread_mutex_t mutex; }; //----------------------------------------------------------------------------- -class PLUGIN_LOGGER : private STG_LOGGER +class PLUGIN_LOGGER { -friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName); +friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER& logger, const std::string& pluginName); public: - PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs); - void operator()(const char * fmt, ...) const; - void operator()(const std::string & line) const; + PLUGIN_LOGGER(const PLUGIN_LOGGER& rhs) : m_parent(rhs.m_parent), m_pluginName(rhs.m_pluginName) {} + void operator()(const char* fmt, ...) const; + void operator()(const std::string& line) const; private: PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn); - std::string pluginName; + const STG_LOGGER& m_parent; + std::string m_pluginName; }; PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName); diff --git a/stglibs/logger.lib/logger.cpp b/stglibs/logger.lib/logger.cpp index 6289618e..4a455257 100644 --- a/stglibs/logger.lib/logger.cpp +++ b/stglibs/logger.lib/logger.cpp @@ -97,18 +97,10 @@ else } } //----------------------------------------------------------------------------- -PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn) - : STG_LOGGER(), - pluginName(pn) +PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER& logger, const std::string& pn) + : m_parent(logger), + m_pluginName(pn) { - SetLogFileName(logger.fileName); -} -//----------------------------------------------------------------------------- -PLUGIN_LOGGER::PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs) - : STG_LOGGER(), - pluginName(rhs.pluginName) -{ - SetLogFileName(fileName); } //----------------------------------------------------------------------------- void PLUGIN_LOGGER::operator()(const char * fmt, ...) const @@ -120,12 +112,12 @@ va_start(vl, fmt); vsnprintf(buff, sizeof(buff), fmt, vl); va_end(vl); -STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), buff); +m_parent("[%s] %s", m_pluginName.c_str(), buff); } //----------------------------------------------------------------------------- void PLUGIN_LOGGER::operator()(const std::string & line) const { -STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), line.c_str()); +m_parent("[%s] %s", m_pluginName.c_str(), line.c_str()); } //----------------------------------------------------------------------------- PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName)