Handle response from host for soft power off request
Change-Id: Ia923eff57f855dc88cb04db13590ae1a58a502fd
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/softoff/mainapp.cpp b/softoff/mainapp.cpp
index f5fbf18..9ed34dd 100644
--- a/softoff/mainapp.cpp
+++ b/softoff/mainapp.cpp
@@ -19,10 +19,10 @@
#include "config.h"
#include "timer.hpp"
-using namespace phosphor::logging;
-
int main(int argc, char** argv)
{
+ using namespace phosphor::logging;
+
// systemd event handler
sd_event* events = nullptr;
@@ -32,13 +32,14 @@
// Add systemd object manager.
sdbusplus::server::manager::manager(bus, SOFTOFF_OBJPATH);
- // sd_event object
+ // sd_event object. StateManager wants that this applicatin return '0'
+ // always.
auto r = sd_event_default(&events);
if (r < 0)
{
log<level::ERR>("Failure to create sd_event handler",
entry("ERROR=%s", strerror(-r)));
- return -1;
+ return 0;
}
// Attach the bus to sd_event to service user requests
@@ -47,12 +48,13 @@
// Create the SoftPowerOff object.
phosphor::ipmi::SoftPowerOff powerObj(bus, events, SOFTOFF_OBJPATH);
- /** @brief Claim the bus */
+ // Claim the bus. Delaying it until sending SMS_ATN may result
+ // in a race condition between this available and IPMI trying to send
+ // message as a reponse to ack from host.
bus.request_name(SOFTOFF_BUSNAME);
- /** @brief Wait for client requests until this application has processed
- * at least one successful SoftPowerOff
- */
+ // Wait for client requests until this application has processed
+ // at least one successful SoftPowerOff or we timed out
while(!powerObj.isCompleted() && !powerObj.isTimerExpired())
{
// -1 denotes wait for ever