diff options
| author | James Feist <james.feist@linux.intel.com> | 2018-08-10 16:39:24 -0700 |
|---|---|---|
| committer | James Feist <james.feist@linux.intel.com> | 2018-08-22 21:12:08 +0000 |
| commit | 64f072a74c895de24b2ec7a5c829224e6abdf516 (patch) | |
| tree | 7d2073416197803dc480ccecec1ccb8239dd18e6 | |
| parent | c065cf1b195f9ccd8fea882ce76416473d4fee7c (diff) | |
| download | phosphor-pid-control-64f072a74c895de24b2ec7a5c829224e6abdf516.tar.gz phosphor-pid-control-64f072a74c895de24b2ec7a5c829224e6abdf516.zip | |
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>
| -rw-r--r-- | dbus/dbusconfiguration.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
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 @@ void init(sdbusplus::bus::bus &bus) 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", |

