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:
Tuur Vanhoutte 2022-07-09 12:24:21 +02:00 committed by GitHub
parent a20f76d7e5
commit 98d584c8fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 11 deletions

View File

@ -44,6 +44,8 @@ class config {
void set_included(file_list included);
file_list get_included_files() const;
void warn_deprecated(const string& section, const string& key, string replacement) const;
/**
@ -225,10 +227,9 @@ class config {
return value;
} catch (const key_error& err) {
return get<T>(section, newkey, fallback);
}
catch (const std::exception& err) {
m_log.err("Invalid value for \"%s.%s\", using fallback key \"%s.%s\" (reason: %s)",
section, old, section, newkey, err.what());
} catch (const std::exception& err) {
m_log.err("Invalid value for \"%s.%s\", using fallback key \"%s.%s\" (reason: %s)", section, old, section, newkey,
err.what());
return get<T>(section, newkey, fallback);
}
}

View File

@ -55,6 +55,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
void signal_handler(int signum);
void conn_cb();
void create_config_watcher(const string& fname);
void confwatch_handler(const char* fname);
void notifier_handler();
void screenshot_handler();

View File

@ -59,6 +59,10 @@ void config::set_included(file_list 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 {
if (has(section, key)) {
m_log.warn(

View File

@ -195,6 +195,16 @@ void controller::signal_handler(int signum) {
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) {
m_log.notice("Watched config file changed %s", filename);
stop(true);
@ -251,13 +261,11 @@ void controller::read_events(bool confwatch) {
}
if (confwatch) {
auto& fs_event_handle = m_loop.handle<FSEventHandle>();
fs_event_handle.start(
m_conf.filepath(), 0, [this](const auto& e) { confwatch_handler(e.path); },
[this, &fs_event_handle](const auto& e) {
m_log.err("libuv error while watching config file for changes: %s", uv_strerror(e.status));
fs_event_handle.close();
});
create_config_watcher(m_conf.filepath());
// also watch the include-files for changes
for (auto& module_path : m_conf.get_included_files()) {
create_config_watcher(module_path);
}
}
if (!m_snapshot_dst.empty()) {