control: Load config file(s) when available
Fan control's config file(s) are loaded when the fan control service
starts if found either in the override location, default location, or
the compatible interface is available. When the required config file(s)
are not found at startup, it waits to receive the interfacesAdded signal
that the compatible interface is available and then loads its config
file(s).
If at any point another interfacesAdded signal for the compatible
interface is received after successfully loading its config file(s),
this signal is ignored. So the only method to reload the config file(s)
is by providing the SIGHUP signal.
Change-Id: I14f93a684bb00a6a32f8cb228cbfb9ce3f022c92
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 4ba61e7..e3de8dc 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -58,14 +58,12 @@
Manager::Manager(const sdeventplus::Event& event) :
_bus(util::SDBusPlus::getBus()), _event(event),
- _mgr(util::SDBusPlus::getBus(), CONTROL_OBJPATH),
+ _mgr(util::SDBusPlus::getBus(), CONTROL_OBJPATH), _loadAllowed(true),
_powerState(std::make_unique<PGoodState>(
util::SDBusPlus::getBus(),
std::bind(std::mem_fn(&Manager::powerStateChanged), this,
std::placeholders::_1)))
-{
- load();
-}
+{}
void Manager::sighupHandler(sdeventplus::source::Signal&,
const struct signalfd_siginfo*)
@@ -78,11 +76,13 @@
try
{
+ _loadAllowed = true;
load();
}
catch (std::runtime_error& re)
{
// Restore saved available and active profiles
+ _loadAllowed = false;
_profiles.swap(profiles);
_activeProfiles.swap(activeProfiles);
log<level::ERR>("Error reloading configs, no changes made",
@@ -92,51 +92,57 @@
void Manager::load()
{
- // Load the available profiles and which are active
- setProfiles();
-
- // Load the zone configurations
- auto zones = getConfig<Zone>(false, _event, this);
- // Load the fan configurations and move each fan into its zone
- auto fans = getConfig<Fan>(false);
- for (auto& fan : fans)
+ if (_loadAllowed)
{
- configKey fanProfile =
- std::make_pair(fan.second->getZone(), fan.first.second);
- auto itZone = std::find_if(
- zones.begin(), zones.end(), [&fanProfile](const auto& zone) {
- return Manager::inConfig(fanProfile, zone.first);
- });
- if (itZone != zones.end())
+ // Load the available profiles and which are active
+ setProfiles();
+
+ // Load the zone configurations
+ auto zones = getConfig<Zone>(false, _event, this);
+ // Load the fan configurations and move each fan into its zone
+ auto fans = getConfig<Fan>(false);
+ for (auto& fan : fans)
{
- if (itZone->second->getTarget() != fan.second->getTarget() &&
- fan.second->getTarget() != 0)
+ configKey fanProfile =
+ std::make_pair(fan.second->getZone(), fan.first.second);
+ auto itZone = std::find_if(
+ zones.begin(), zones.end(), [&fanProfile](const auto& zone) {
+ return Manager::inConfig(fanProfile, zone.first);
+ });
+ if (itZone != zones.end())
{
- // Update zone target to current target of the fan in the
- // zone
- itZone->second->setTarget(fan.second->getTarget());
+ if (itZone->second->getTarget() != fan.second->getTarget() &&
+ fan.second->getTarget() != 0)
+ {
+ // Update zone target to current target of the fan in the
+ // zone
+ itZone->second->setTarget(fan.second->getTarget());
+ }
+ itZone->second->addFan(std::move(fan.second));
}
- itZone->second->addFan(std::move(fan.second));
}
+
+ // Load any events configured
+ auto events = getConfig<Event>(true, this, zones);
+
+ // Enable zones
+ _zones = std::move(zones);
+ std::for_each(_zones.begin(), _zones.end(),
+ [](const auto& entry) { entry.second->enable(); });
+
+ // Clear current timers and signal subscriptions before enabling events
+ // To save reloading services and/or objects into cache, do not clear
+ // cache
+ _timers.clear();
+ _signals.clear();
+
+ // Enable events
+ _events = std::move(events);
+ std::for_each(_events.begin(), _events.end(),
+ [](const auto& entry) { entry.second->enable(); });
+
+ _loadAllowed = false;
}
-
- // Load any events configured
- auto events = getConfig<Event>(true, this, zones);
-
- // Enable zones
- _zones = std::move(zones);
- std::for_each(_zones.begin(), _zones.end(),
- [](const auto& entry) { entry.second->enable(); });
-
- // Clear current timers and signal subscriptions before enabling events
- // To save reloading services and/or objects into cache, do not clear cache
- _timers.clear();
- _signals.clear();
-
- // Enable events
- _events = std::move(events);
- std::for_each(_events.begin(), _events.end(),
- [](const auto& entry) { entry.second->enable(); });
}
void Manager::powerStateChanged(bool powerStateOn)