presence: Only allow loading once
If entity manager were to get restarted, the JsonConfig::start()
function would be called again which would attempt to load a config on
top of an existing one.
Fix that by only allowing the config to load once. If someone wanted
the config to load again, they could either send the HUP signal or just
restart the service.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I1526db17500ffe88408c8bc1f0abba9c4952107b
diff --git a/presence/json_parser.cpp b/presence/json_parser.cpp
index d4f121f..e09317b 100644
--- a/presence/json_parser.cpp
+++ b/presence/json_parser.cpp
@@ -59,11 +59,17 @@
{
using config = fan::JsonConfig;
- process(config::load(config::getConfFile(_bus, confAppName, confFileName)));
-
- for (auto& p : _policies)
+ if (!_loaded)
{
- p->monitor();
+ process(
+ config::load(config::getConfFile(_bus, confAppName, confFileName)));
+
+ _loaded = true;
+
+ for (auto& p : _policies)
+ {
+ p->monitor();
+ }
}
}
diff --git a/presence/json_parser.hpp b/presence/json_parser.hpp
index fc60229..dfd2ce2 100644
--- a/presence/json_parser.hpp
+++ b/presence/json_parser.hpp
@@ -106,6 +106,11 @@
std::unique_ptr<ErrorReporter> _reporter;
/**
+ * Tracks if the config has already been loaded.
+ */
+ bool _loaded = false;
+
+ /**
* @brief Process the json config to extract the defined fan presence
* policies.
*