main: Terminate cleanly for TERM and INT

This makes it possible to instrument the application for memory leaks
and other required sanitization at termination.

Change-Id: I94741c4df746d5cc65ce77ad5cf86ef505b7576b
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/main.cpp b/main.cpp
index e84f144..3a3b4ce 100644
--- a/main.cpp
+++ b/main.cpp
@@ -30,6 +30,8 @@
 #include <sdeventplus/event.hpp>
 #include <sdeventplus/source/event.hpp>
 #include <sdeventplus/source/io.hpp>
+#include <sdeventplus/source/signal.hpp>
+#include <stdplus/signal.hpp>
 #include <thread>
 
 static size_t codeSize = 1; /* Size of each POST code in bytes */
@@ -184,6 +186,15 @@
         }
         // Enable bus to handle incoming IO and bus events
         bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
+        auto intCb = [](sdeventplus::source::Signal& source,
+                        const struct signalfd_siginfo*) {
+            source.get_event().exit(0);
+        };
+        stdplus::signal::block(SIGINT);
+        sdeventplus::source::Signal(event, SIGINT, intCb).set_floating(true);
+        stdplus::signal::block(SIGTERM);
+        sdeventplus::source::Signal(event, SIGTERM, std::move(intCb))
+            .set_floating(true);
         rc = event.loop();
     }
     catch (const std::exception& e)