From 98d584c8fe5924a271bb213e2f9d6480b22d17b9 Mon Sep 17 00:00:00 2001 From: Tuur Vanhoutte <4633209+zjeffer@users.noreply.github.com> Date: Sat, 9 Jul 2022 12:24:21 +0200 Subject: [PATCH] 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 --- include/components/config.hpp | 9 +++++---- include/components/controller.hpp | 1 + src/components/config.cpp | 4 ++++ src/components/controller.cpp | 22 +++++++++++++++------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/components/config.hpp b/include/components/config.hpp index b3a894e6..d0be66d4 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -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(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(section, newkey, fallback); } } diff --git a/include/components/controller.hpp b/include/components/controller.hpp index 0eec49c0..cb0a72e7 100644 --- a/include/components/controller.hpp +++ b/include/components/controller.hpp @@ -55,6 +55,7 @@ class controller : public signal_receiver(); + 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(); - 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()) {