Also monitor include-files for changes when --reload is set (#2759)
* fixes #675 * feat(configwatcher): method to create config monitor handler * cleanup Co-authored-by: patrick96 <p.ziegler96@gmail.com>
This commit is contained in:
parent
a20f76d7e5
commit
98d584c8fe
@ -44,6 +44,8 @@ class config {
|
|||||||
|
|
||||||
void set_included(file_list included);
|
void set_included(file_list included);
|
||||||
|
|
||||||
|
file_list get_included_files() const;
|
||||||
|
|
||||||
void warn_deprecated(const string& section, const string& key, string replacement) const;
|
void warn_deprecated(const string& section, const string& key, string replacement) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -225,10 +227,9 @@ class config {
|
|||||||
return value;
|
return value;
|
||||||
} catch (const key_error& err) {
|
} catch (const key_error& err) {
|
||||||
return get<T>(section, newkey, fallback);
|
return get<T>(section, newkey, fallback);
|
||||||
}
|
} catch (const std::exception& err) {
|
||||||
catch (const std::exception& err) {
|
m_log.err("Invalid value for \"%s.%s\", using fallback key \"%s.%s\" (reason: %s)", section, old, section, newkey,
|
||||||
m_log.err("Invalid value for \"%s.%s\", using fallback key \"%s.%s\" (reason: %s)",
|
err.what());
|
||||||
section, old, section, newkey, err.what());
|
|
||||||
return get<T>(section, newkey, fallback);
|
return get<T>(section, newkey, fallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
|
|||||||
void signal_handler(int signum);
|
void signal_handler(int signum);
|
||||||
|
|
||||||
void conn_cb();
|
void conn_cb();
|
||||||
|
void create_config_watcher(const string& fname);
|
||||||
void confwatch_handler(const char* fname);
|
void confwatch_handler(const char* fname);
|
||||||
void notifier_handler();
|
void notifier_handler();
|
||||||
void screenshot_handler();
|
void screenshot_handler();
|
||||||
|
@ -59,6 +59,10 @@ void config::set_included(file_list included) {
|
|||||||
m_included = move(included);
|
m_included = move(included);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file_list config::get_included_files() const {
|
||||||
|
return m_included;
|
||||||
|
}
|
||||||
|
|
||||||
void config::ignore_key(const string& section, const string& key) const {
|
void config::ignore_key(const string& section, const string& key) const {
|
||||||
if (has(section, key)) {
|
if (has(section, key)) {
|
||||||
m_log.warn(
|
m_log.warn(
|
||||||
|
@ -195,6 +195,16 @@ void controller::signal_handler(int signum) {
|
|||||||
stop(signum == SIGUSR1);
|
stop(signum == SIGUSR1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void controller::create_config_watcher(const string& filename) {
|
||||||
|
auto& fs_event_handler = m_loop.handle<FSEventHandle>();
|
||||||
|
fs_event_handler.start(
|
||||||
|
filename, 0, [this](const auto& e) { confwatch_handler(e.path); },
|
||||||
|
[this, &fs_event_handler](const auto& e) {
|
||||||
|
m_log.err("libuv error while watching included file for changes: %s", uv_strerror(e.status));
|
||||||
|
fs_event_handler.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void controller::confwatch_handler(const char* filename) {
|
void controller::confwatch_handler(const char* filename) {
|
||||||
m_log.notice("Watched config file changed %s", filename);
|
m_log.notice("Watched config file changed %s", filename);
|
||||||
stop(true);
|
stop(true);
|
||||||
@ -251,13 +261,11 @@ void controller::read_events(bool confwatch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (confwatch) {
|
if (confwatch) {
|
||||||
auto& fs_event_handle = m_loop.handle<FSEventHandle>();
|
create_config_watcher(m_conf.filepath());
|
||||||
fs_event_handle.start(
|
// also watch the include-files for changes
|
||||||
m_conf.filepath(), 0, [this](const auto& e) { confwatch_handler(e.path); },
|
for (auto& module_path : m_conf.get_included_files()) {
|
||||||
[this, &fs_event_handle](const auto& e) {
|
create_config_watcher(module_path);
|
||||||
m_log.err("libuv error while watching config file for changes: %s", uv_strerror(e.status));
|
}
|
||||||
fs_event_handle.close();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_snapshot_dst.empty()) {
|
if (!m_snapshot_dst.empty()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user