control: Dump flight recorder on abnormal exit
Fan control throws exceptions when something goes wrong in order to
crash and possibly kill the watchdog. In this case, dump the flight
recorder. There are two paths because some exceptions just exit the app
so that a core dump isn't taken, since these are due to D-Bus problems
where core dumps aren't necessary.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I118517e186f8af434f95a528c2c7f1ecdbe7d337
diff --git a/control/main.cpp b/control/main.cpp
index dcd4679..ba9c612 100644
--- a/control/main.cpp
+++ b/control/main.cpp
@@ -16,6 +16,7 @@
#include "config.h"
#ifndef CONTROL_USE_JSON
+#include "../utils/flight_recorder.hpp"
#include "argument.hpp"
#include "manager.hpp"
#else
@@ -70,6 +71,8 @@
try
{
#ifdef CONTROL_USE_JSON
+ phosphor::fan::control::json::FlightRecorder::instance().log("main",
+ "Startup");
json::Manager manager(event);
// Handle loading fan control's config file(s)
@@ -127,6 +130,21 @@
entry("INTERFACE=%s", e.interface.c_str()),
entry("PROPERTY=%s", e.property.c_str()));
}
+ catch (std::exception& e)
+ {
+#ifdef CONTROL_USE_JSON
+ phosphor::fan::control::json::FlightRecorder::instance().log(
+ "main", "Unexpected exception exit");
+ phosphor::fan::control::json::FlightRecorder::instance().dump();
+#endif
+ throw;
+ }
+
+#ifdef CONTROL_USE_JSON
+ phosphor::fan::control::json::FlightRecorder::instance().log(
+ "main", "Abnormal exit");
+ phosphor::fan::control::json::FlightRecorder::instance().dump();
+#endif
return 1;
}