summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVernon Mauery <vernon.mauery@linux.intel.com>2019-03-13 13:11:25 -0700
committerVernon Mauery <vernon.mauery@linux.intel.com>2019-03-20 13:26:06 -0700
commit1b7f6f2d01b955cecb79eea8cc21f6fe387ce1f1 (patch)
treeb1f7d52984c4466c3637709d4a59a70f0fcce03a
parent3719c2fc50d33dbe407eb5351d94252406ccec9e (diff)
downloadphosphor-host-ipmid-1b7f6f2d01b955cecb79eea8cc21f6fe387ce1f1.tar.gz
phosphor-host-ipmid-1b7f6f2d01b955cecb79eea8cc21f6fe387ce1f1.zip
make ipmid respond to SIGTERM and SIGINT for clean shutdown
On some systems ipmid was not responding to SIGTERM so systemd could not shut it down in a clean manner, resorting to SIGKILL after a long timeout. This adds code to respond to SIGTERM and SIGINT and safely unwind all the provider libraries on exit. Tested-by: running ipmid; in another shell, and running 'killall -15 ipmid' or 'killall -2 ipmid' to send SIGTERM or SIGINT and watch that ipmid shuts down in a controlled and timely manner. Change-Id: I690846796523bebea1a08845c0d17e1df2a94fee Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
-rw-r--r--ipmid-new.cpp24
-rw-r--r--transporthandler.cpp3
2 files changed, 21 insertions, 6 deletions
diff --git a/ipmid-new.cpp b/ipmid-new.cpp
index bf7795c..24d1ce5 100644
--- a/ipmid-new.cpp
+++ b/ipmid-new.cpp
@@ -63,9 +63,6 @@ namespace fs = std::filesystem;
using namespace phosphor::logging;
-// Global timer for network changes
-std::unique_ptr<phosphor::Timer> networkTimer = nullptr;
-
// IPMI Spec, shared Reservation ID.
static unsigned short selReservationID = 0xFFFF;
static bool selReservationValid = false;
@@ -560,7 +557,7 @@ using CommandHandler = phosphor::host::command::CommandHandler;
std::unique_ptr<phosphor::host::command::Manager> cmdManager;
void ipmid_send_cmd_to_host(CommandHandler&& cmd)
{
- return cmdManager->execute(std::move(cmd));
+ return cmdManager->execute(std::forward<CommandHandler>(cmd));
}
std::unique_ptr<phosphor::host::command::Manager>& ipmid_get_host_cmd_manager()
@@ -619,9 +616,26 @@ int main(int argc, char* argv[])
handleLegacyIpmiCommand);
#endif /* ALLOW_DEPRECATED_API */
+ // set up boost::asio signal handling
+ std::function<SignalResponse(int)> stopAsioRunLoop =
+ [&io](int signalNumber) {
+ log<level::INFO>("Received signal; quitting",
+ entry("SIGNAL=%d", signalNumber));
+ io->stop();
+ return SignalResponse::breakExecution;
+ };
+ registerSignalHandler(ipmi::prioOpenBmcBase, SIGINT, stopAsioRunLoop);
+ registerSignalHandler(ipmi::prioOpenBmcBase, SIGTERM, stopAsioRunLoop);
+
io->run();
- // This avoids a warning about unused variables
+ // destroy all the IPMI handlers so the providers can unload safely
+ ipmi::handlerMap.clear();
+ ipmi::groupHandlerMap.clear();
+ ipmi::oemHandlerMap.clear();
+ ipmi::filterList.clear();
+ // unload the provider libraries
handles.clear();
+
return 0;
}
diff --git a/transporthandler.cpp b/transporthandler.cpp
index 0b5a00c..24fea47 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -37,7 +37,8 @@ namespace filesystem = std::experimental::filesystem;
#error filesystem not available
#endif
-extern std::unique_ptr<phosphor::Timer> networkTimer;
+// timer for network changes
+std::unique_ptr<phosphor::Timer> networkTimer = nullptr;
const int SIZE_MAC = 18; // xx:xx:xx:xx:xx:xx
constexpr auto ipv4Protocol = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
OpenPOWER on IntegriCloud