Resolve obmc-standby.target into a path
A slight modification to bmc_state_manager.cpp.
Added a systemd call GetUnit to derive the
obmc-standby.target instead of using a hard
coded string such as obmc_2dstandby_2etarget.
Change-Id: Ica1e1e9c327e68190e800e88c0db865922c7443f
Signed-off-by: Josh D. King <jdking@us.ibm.com>
diff --git a/bmc_state_manager.cpp b/bmc_state_manager.cpp
index 03026ff..4559c80 100644
--- a/bmc_state_manager.cpp
+++ b/bmc_state_manager.cpp
@@ -25,26 +25,50 @@
{server::BMC::Transition::Reboot, "reboot.target"}
};
-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_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;
+ sdbusplus::message::object_path unitTargetPath;
auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_TGT_PATH,
- SYSTEMD_PRP_INTERFACE,
- "Get");
+ SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE,
+ "GetUnit");
+
+ method.append(obmcStandbyTarget);
+
+ auto result = this->bus.call(method);
+
+ //Check that the bus call didn't result in an error
+ if(result.is_method_error())
+ {
+ log<level::ERR>("Error in bus call.");
+ return;
+ }
+
+ result.read(unitTargetPath);
+
+ method = this->bus.new_method_call(SYSTEMD_SERVICE,
+ static_cast<const std::string&>
+ (unitTargetPath).c_str(),
+ SYSTEMD_PRP_INTERFACE,
+ "Get");
method.append("org.freedesktop.systemd1.Unit", "ActiveState");
- auto result = this->bus.call(method);
+ result = this->bus.call(method);
+
+ //Check that the bus call didn't result in an error
+ if(result.is_method_error())
+ {
+ log<level::INFO>("Error in bus call.");
+ return;
+ }
//Is obmc-standby.target active or inactive?
result.read(currentState);