dbusConfiguration: restart on configuration change

Watch for dbus interface changes and stop the daemon
when they happen. Systemd should restart us if we have
the correct service file written.

Tested-by: Used new add object entity-manager interface
and noticed daemon restart when new config was added.

Change-Id: I708447dbb6ed2ab23b60036d310606ef7a1a7d3b
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index 4c354c1..c3ca365 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -14,11 +14,15 @@
 // limitations under the License.
 */
 
+#include <chrono>
 #include <conf.hpp>
 #include <dbus/util.hpp>
+#include <functional>
 #include <iostream>
 #include <sdbusplus/bus.hpp>
+#include <sdbusplus/bus/match.hpp>
 #include <set>
+#include <thread>
 #include <unordered_map>
 
 static constexpr bool DEBUG = false; // enable to print found configuration
@@ -127,6 +131,23 @@
                                sdbusplus::message::variant<
                                    uint64_t, int64_t, double, std::string,
                                    std::vector<std::string>>>>>;
+
+    // install watch for properties changed
+    std::function<void(sdbusplus::message::message & message)> eventHandler =
+        [](const sdbusplus::message::message &) {
+            // do a brief sleep as we tend to get a bunch of these events at
+            // once
+            std::this_thread::sleep_for(std::chrono::seconds(5));
+            std::cout << "New configuration detected, restarting\n.";
+            std::exit(EXIT_SUCCESS); // service file should make us restart
+        };
+
+    static sdbusplus::bus::match::match match(
+        bus,
+        "type='signal',member='PropertiesChanged',arg0namespace='" +
+            std::string(pidConfigurationInterface) + "'",
+        eventHandler);
+
     auto mapper =
         bus.new_method_call("xyz.openbmc_project.ObjectMapper",
                             "/xyz/openbmc_project/object_mapper",