Prevent config reload after initial save.

This commit is contained in:
XMRig 2019-02-15 07:06:48 +07:00
parent f4d2dec628
commit 14e7c82512
6 changed files with 31 additions and 13 deletions

View file

@ -74,13 +74,7 @@ xmrig::CommonConfig::CommonConfig() :
m_colors(true),
m_dryRun(false),
m_syslog(false),
# ifdef XMRIG_PROXY_PROJECT
m_watch(true),
# else
m_watch(false), // TODO: enable config file watch by default when this feature propertly handled and tested.
# endif
m_apiPort(0),
m_donateLevel(kDefaultDonateLevel),
m_printTime(60),

View file

@ -23,6 +23,7 @@
*/
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <uv.h>
@ -145,6 +146,19 @@ bool xmrig::ConfigLoader::reload(xmrig::IConfig *oldConfig, const char *json)
}
bool xmrig::ConfigLoader::watch(IConfig *config)
{
if (!config->isWatch()) {
return false;
}
assert(m_watcher == nullptr);
m_watcher = new xmrig::ConfigWatcher(config->fileName(), m_creator, m_listener);
return true;
}
xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *creator, IConfigListener *listener)
{
m_creator = creator;
@ -192,10 +206,6 @@ xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *crea
return nullptr;
}
if (config->isWatch()) {
m_watcher = new xmrig::ConfigWatcher(config->fileName(), creator, listener);
}
return config;
}

View file

@ -52,6 +52,7 @@ public:
static bool loadFromJSON(IConfig *config, const char *json);
static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc);
static bool reload(IConfig *oldConfig, const char *json);
static bool watch(IConfig *config);
static IConfig *load(Process *process, IConfigCreator *creator, IConfigListener *listener);
static void release();

View file

@ -147,6 +147,20 @@ void xmrig::Controller::addListener(IControllerListener *listener)
}
void xmrig::Controller::save()
{
if (!config()) {
return;
}
if (d_ptr->config->isShouldSave()) {
d_ptr->config->save();
}
ConfigLoader::watch(d_ptr->config);
}
void xmrig::Controller::onNewConfig(IConfig *config)
{
Config *previousConfig = d_ptr->config;

View file

@ -54,6 +54,7 @@ public:
int init();
Network *network() const;
void addListener(IControllerListener *listener);
void save();
protected:
void onNewConfig(IConfig *config) override;

View file

@ -206,9 +206,7 @@ void Workers::start(xmrig::Controller *controller)
handle->start(Workers::onReady);
}
if (controller->config()->isShouldSave()) {
controller->config()->save();
}
controller->save();
}