Rework setNmiProperty to use yielding Dbus API
setNmiProperty was the last holdout making blocking Dbus calls in the
ipmiChassisControl function. This converts the blocking calls to
yielding calls, making use of the Context object.
Tested: ipmitool chassis power diag
Check host to see that it recieved an NMI
Change-Id: I4d96752b020947cc08a1e985213afc1af735344d
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/chassishandler.cpp b/chassishandler.cpp
index f4d9209..737d3d2 100644
--- a/chassishandler.cpp
+++ b/chassishandler.cpp
@@ -886,7 +886,7 @@
// Set Enabled property to inform NMI source
// handling to trigger a NMI_OUT BSOD.
//------------------------------------------
-int setNmiProperty(const bool value)
+int setNmiProperty(ipmi::Context::ptr& ctx, const bool value)
{
constexpr const char* nmiSourceObjPath =
"/xyz/openbmc_project/Chassis/Control/NMISource";
@@ -894,20 +894,24 @@
"xyz.openbmc_project.Chassis.Control.NMISource";
std::string bmcSourceSignal = "xyz.openbmc_project.Chassis.Control."
"NMISource.BMCSourceSignal.ChassisCmd";
- std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
- try
+ std::string service;
+ boost::system::error_code ec =
+ ipmi::getService(ctx, nmiSourceIntf, nmiSourceObjPath, service);
+ if (!ec)
{
- auto service = ipmi::getService(*busp, nmiSourceIntf, nmiSourceObjPath);
- ipmi::setDbusProperty(*busp, service, nmiSourceObjPath, nmiSourceIntf,
- "BMCSource", bmcSourceSignal);
- ipmi::setDbusProperty(*busp, service, nmiSourceObjPath, nmiSourceIntf,
- "Enabled", value);
+ ec = ipmi::setDbusProperty(ctx, service, nmiSourceObjPath,
+ nmiSourceIntf, "BMCSource", bmcSourceSignal);
}
- catch (const std::exception& e)
+ if (!ec)
+ {
+ ec = ipmi::setDbusProperty(ctx, service, nmiSourceObjPath,
+ nmiSourceIntf, "Enabled", value);
+ }
+ if (ec)
{
log<level::ERR>("Failed to trigger NMI_OUT",
- entry("EXCEPTION=%s", e.what()));
+ entry("EXCEPTION=%s", ec.message().c_str()));
return -1;
}
@@ -1344,7 +1348,7 @@
rc = initiateHostStateTransition(ctx, State::Host::Transition::Off);
break;
case CMD_PULSE_DIAGNOSTIC_INTR:
- rc = setNmiProperty(true);
+ rc = setNmiProperty(ctx, true);
break;
default: