summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh D. King <jdking@us.ibm.com>2017-02-02 11:09:11 -0600
committerAndrew Geissler <geissonator@yahoo.com>2017-02-10 21:20:00 +0000
commitd3e58474dad16a9e215df1687f72dd9f80f0c231 (patch)
tree0be8ff8cf5c106c8f4a045be9f38ad0338fd7382
parent20a4887fa02492d854ea131ffd5775512196e975 (diff)
downloadphosphor-state-manager-d3e58474dad16a9e215df1687f72dd9f80f0c231.tar.gz
phosphor-state-manager-d3e58474dad16a9e215df1687f72dd9f80f0c231.zip
Add discovery of initial state
Added the method discoverInitialState that will be used to determine if the obmc-standby.target is either active or inactive. This catches the race condition that could happen if just our app was restarted and the signal had already been given and we had missed it. Change-Id: Iadcdcbd2d1045fa62491e9af6e2402d4b17c4a60 Signed-off-by: Josh D. King <jdking@us.ibm.com>
-rw-r--r--bmc_state_manager.cpp47
-rw-r--r--bmc_state_manager.hpp9
2 files changed, 55 insertions, 1 deletions
diff --git a/bmc_state_manager.cpp b/bmc_state_manager.cpp
index a0308cd..35a62e8 100644
--- a/bmc_state_manager.cpp
+++ b/bmc_state_manager.cpp
@@ -17,6 +17,7 @@ using namespace phosphor::logging;
constexpr auto obmcStandbyTarget = "obmc-standby.target";
constexpr auto signalDone = "done";
+constexpr auto activeState = "active";
/* Map a transition to it's systemd target */
const std::map<server::BMC::Transition, const char*> SYSTEMD_TABLE =
@@ -28,6 +29,52 @@ constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
+constexpr auto SYSTEMD_PRP_INTERFACE = "org.freedesktop.DBus.Properties";
+constexpr auto SYSTEMD_TGT_PATH = "/org/freedesktop/systemd1/unit/"
+ "obmc_2dstandby_2etarget";
+
+void BMC::discoverInitialState()
+{
+ sdbusplus::message::variant<std::string> currentState;
+
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
+ SYSTEMD_TGT_PATH,
+ SYSTEMD_PRP_INTERFACE,
+ "Get");
+
+ method.append("org.freedesktop.systemd1.Unit", "ActiveState");
+
+ auto result = this->bus.call(method);
+
+ //Is obmc-standby.target active or inactive?
+ result.read(currentState);
+
+ if(currentState == activeState)
+ {
+ log<level::INFO>("Setting the BMCState field",
+ entry("CURRENT_BMC_STATE=%s",
+ "BMC_READY"));
+ this->currentBMCState(BMCState::Ready);
+
+ //Unsubscribe so we stop processing all other signals
+ method = this->bus.new_method_call(SYSTEMD_SERVICE,
+ SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE,
+ "Unsubscribe");
+ this->bus.call(method);
+ this->stateSignal.release();
+ }
+ else
+ {
+ log<level::INFO>("Setting the BMCState field",
+ entry("CURRENT_BMC_STATE=%s",
+ "BMC_NOTREADY"));
+ this->currentBMCState(BMCState::NotReady);
+ }
+
+ return;
+}
+
void BMC::subscribeToSystemdSignals()
{
auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
diff --git a/bmc_state_manager.hpp b/bmc_state_manager.hpp
index bbace38..0e52a25 100644
--- a/bmc_state_manager.hpp
+++ b/bmc_state_manager.hpp
@@ -29,7 +29,7 @@ class BMC : public sdbusplus::server::object::object<
const char* objPath) :
sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::State::server::BMC>(
- bus, objPath),
+ bus, objPath, true),
bus(bus),
stateSignal(
std::make_unique<
@@ -43,6 +43,8 @@ class BMC : public sdbusplus::server::object::object<
this))
{
subscribeToSystemdSignals();
+ discoverInitialState();
+ this->emit_object_added();
};
/** @brief Set value of BMCTransition **/
@@ -53,6 +55,11 @@ class BMC : public sdbusplus::server::object::object<
private:
/**
+ * @brief discover the state of the bmc
+ **/
+ void discoverInitialState();
+
+ /**
* @brief subscribe to the systemd signals
**/
void subscribeToSystemdSignals();
OpenPOWER on IntegriCloud