regs: Handle HUP signals

Enable capturing and handling a HUP signal to reload configuration data.

Tested:
    Handler function called upon receiving a SIGHUP

Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Change-Id: I41d136ede5f2a4c0bf595ee58993a4408f153013
diff --git a/phosphor-regulators/src/main.cpp b/phosphor-regulators/src/main.cpp
index 35a3b49..04d3e21 100644
--- a/phosphor-regulators/src/main.cpp
+++ b/phosphor-regulators/src/main.cpp
@@ -18,6 +18,10 @@
 
 #include <sdbusplus/bus.hpp>
 #include <sdeventplus/event.hpp>
+#include <sdeventplus/source/signal.hpp>
+#include <stdplus/signal.hpp>
+
+#include <functional>
 
 int main(void)
 {
@@ -29,5 +33,12 @@
 
     regulators::Manager manager(bus, event);
 
+    // Handle HUP signals
+    stdplus::signal::block(SIGHUP);
+    sdeventplus::source::Signal signal(
+        event, SIGHUP,
+        std::bind(&regulators::Manager::sighupHandler, &manager,
+                  std::placeholders::_1, std::placeholders::_2));
+
     return event.loop();
 }
diff --git a/phosphor-regulators/src/manager.cpp b/phosphor-regulators/src/manager.cpp
index d7743b7..15071d5 100644
--- a/phosphor-regulators/src/manager.cpp
+++ b/phosphor-regulators/src/manager.cpp
@@ -68,6 +68,12 @@
     // collect/update telemetry for each regulator
 }
 
+void Manager::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/,
+                            const struct signalfd_siginfo* /*sigInfo*/)
+{
+    // TODO Reload and process the configuration data
+}
+
 } // namespace regulators
 } // namespace power
 } // namespace phosphor
diff --git a/phosphor-regulators/src/manager.hpp b/phosphor-regulators/src/manager.hpp
index 2b38821..b6560f6 100644
--- a/phosphor-regulators/src/manager.hpp
+++ b/phosphor-regulators/src/manager.hpp
@@ -4,6 +4,7 @@
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/object.hpp>
 #include <sdeventplus/event.hpp>
+#include <sdeventplus/source/signal.hpp>
 #include <sdeventplus/utility/timer.hpp>
 
 namespace phosphor::power::regulators
@@ -53,6 +54,16 @@
      */
     void timerExpired();
 
+    /**
+     * @brief Callback function to handle receiving a HUP signal
+     * to reload the configuration data.
+     *
+     * @param[in] sigSrc - sd_event_source signal wrapper
+     * @param[in] sigInfo - signal info on signal fd
+     */
+    void sighupHandler(sdeventplus::source::Signal& sigSrc,
+                       const struct signalfd_siginfo* sigInfo);
+
   private:
     /**
      * The dbus bus
diff --git a/phosphor-regulators/src/meson.build b/phosphor-regulators/src/meson.build
index 1bf0fb5..9d82033 100644
--- a/phosphor-regulators/src/meson.build
+++ b/phosphor-regulators/src/meson.build
@@ -43,7 +43,8 @@
         libi2c_dep,
         phosphor_logging,
         sdbusplus,
-        sdeventplus
+        sdeventplus,
+        stdplus
     ],
     link_with: phosphor_regulators_library,
     implicit_include_directories: false,