diff options
author | William A. Kennington III <wak@google.com> | 2018-05-11 00:03:12 -0700 |
---|---|---|
committer | William A. Kennington III <wak@google.com> | 2018-05-30 11:00:45 -0700 |
commit | 09568ff7d87186080b5cd3032e7ad4658c676eee (patch) | |
tree | 2cda1983b961ddf3f6dc91e9af402f4baabc9e83 | |
parent | d69c677b9074addf6747c150ad820dd81fc77e81 (diff) | |
download | phosphor-state-manager-09568ff7d87186080b5cd3032e7ad4658c676eee.tar.gz phosphor-state-manager-09568ff7d87186080b5cd3032e7ad4658c676eee.zip |
chassis-state-manager: Clean up sdbusplus exception handling
In order to support error handling for message operations, we need to
make sure we are catching exceptions thrown by sdbusplus.
Tested:
Built / ran on a fully tray pulled zaius. Correctly detected the
host was off and did the automatic transition to boot the machine
at BMC start. Chassis power commands still work as expected and
show up as state transitions.
Change-Id: I3468209b215df6535bb5357a62335da151d81897
Signed-off-by: William A. Kennington III <wak@google.com>
-rw-r--r-- | chassis_state_manager.cpp | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/chassis_state_manager.cpp b/chassis_state_manager.cpp index d78a6f7..f333254 100644 --- a/chassis_state_manager.cpp +++ b/chassis_state_manager.cpp @@ -1,4 +1,5 @@ #include <sdbusplus/bus.hpp> +#include <sdbusplus/exception.hpp> #include <phosphor-logging/log.hpp> #include <phosphor-logging/elog-errors.hpp> #include "xyz/openbmc_project/Common/error.hpp" @@ -22,6 +23,7 @@ namespace manager namespace server = sdbusplus::xyz::openbmc_project::State::server; using namespace phosphor::logging; +using sdbusplus::exception::SdBusError; constexpr auto CHASSIS_STATE_POWEROFF_TGT = "obmc-chassis-poweroff@0.target"; constexpr auto CHASSIS_STATE_HARD_POWEROFF_TGT = @@ -66,7 +68,23 @@ void Chassis::determineInitialState() method.append("org.openbmc.control.Power", "pgood"); auto reply = this->bus.call(method); - reply.read(pgood); + if (reply.is_method_error()) + { + log<level::ERR>("Error in bus call - could not get initial pgood"); + goto fail; + } + + try + { + reply.read(pgood); + } + catch (const SdBusError& e) + { + log<level::ERR>("Error in bus response - bad encoding of pgood", + entry("ERROR=%s", e.what()), + entry("REPLY_SIG=%s", reply.get_signature())); + goto fail; + } if (pgood == 1) { @@ -75,16 +93,16 @@ void Chassis::determineInitialState() convertForMessage(PowerState::On).c_str())); server::Chassis::currentPowerState(PowerState::On); server::Chassis::requestedPowerTransition(Transition::On); - } - else - { - log<level::INFO>("Initial Chassis State will be Off", - entry("CHASSIS_CURRENT_POWER_STATE=%s", - convertForMessage(PowerState::Off).c_str())); - server::Chassis::currentPowerState(PowerState::Off); - server::Chassis::requestedPowerTransition(Transition::Off); + return; } +fail: + log<level::INFO>("Initial Chassis State will be Off", + entry("CHASSIS_CURRENT_POWER_STATE=%s", + convertForMessage(PowerState::Off).c_str())); + server::Chassis::currentPowerState(PowerState::Off); + server::Chassis::requestedPowerTransition(Transition::Off); + return; } @@ -122,7 +140,17 @@ bool Chassis::stateActive(const std::string& target) return false; } - result.read(unitTargetPath); + try + { + result.read(unitTargetPath); + } + catch (const SdBusError& e) + { + log<level::ERR>("Error in bus response - bad encoding for GetUnit", + entry("ERROR=%s", e.what()), + entry("REPLY_SIG=%s", result.get_signature())); + return false; + } method = this->bus.new_method_call( SYSTEMD_SERVICE, @@ -159,7 +187,17 @@ int Chassis::sysStateChange(sdbusplus::message::message& msg) std::string newStateResult{}; // Read the msg and populate each variable - msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); + try + { + msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); + } + catch (const SdBusError& e) + { + log<level::ERR>("Error in state change - bad encoding", + entry("ERROR=%s", e.what()), + entry("REPLY_SIG=%s", msg.get_signature())); + return 0; + } if ((newStateUnit == CHASSIS_STATE_POWEROFF_TGT) && (newStateResult == "done") && (!stateActive(CHASSIS_STATE_POWERON_TGT))) |