control: Dump flight recorder on signal SIGUSR1

Add a SIGUSR1 handler to dump the flight recorder.

It uses the sdventplus sd_event_add_defer wrapper to do the dump when
the code gets back to the event loop so it doesn't spend the time doing
it inside the signal handler itself.

The flight recorder can now be dumped with:
    kill -USR1 $(pidof phosphor-fan-control)
    or
    systemctl kill -s USR1 phosphor-fan-control@0

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I46e45cb7a5e42ea4d217f63a8e14b6ef02ed8c22
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 691c11f..fb997c5 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -17,6 +17,7 @@
 
 #include "manager.hpp"
 
+#include "../utils/flight_recorder.hpp"
 #include "action.hpp"
 #include "event.hpp"
 #include "fan.hpp"
@@ -91,6 +92,20 @@
     }
 }
 
+void Manager::sigUsr1Handler(sdeventplus::source::Signal&,
+                             const struct signalfd_siginfo*)
+{
+    _flightRecEventSource = std::make_unique<sdeventplus::source::Defer>(
+        _event, std::bind(std::mem_fn(&Manager::dumpFlightRecorder), this,
+                          std::placeholders::_1));
+}
+
+void Manager::dumpFlightRecorder(sdeventplus::source::EventBase& /*source*/)
+{
+    FlightRecorder::instance().dump();
+    _flightRecEventSource.reset();
+}
+
 void Manager::load()
 {
     if (_loadAllowed)