network_manager: Add reload post hooks
We need this to handle deleting interfaces after reloading.
Change-Id: I0f3ca4cedf0e112bc285e4e2ecc1c3cad8ef5677
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index 7e540d1..014d0b4 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -517,7 +517,21 @@
{
log<level::ERR>("Failed to reload configuration",
entry("ERR=%s", ex.what()));
+ reloadPostHooks.clear();
}
+ for (auto& hook : reloadPostHooks)
+ {
+ try
+ {
+ hook();
+ }
+ catch (const std::exception& ex)
+ {
+ log<level::ERR>("Failed executing reload hook, ignoring",
+ entry("ERR=%s", ex.what()));
+ }
+ }
+ reloadPostHooks.clear();
}
void Manager::handleAdminState(std::string_view state, unsigned ifidx)
diff --git a/src/network_manager.hpp b/src/network_manager.hpp
index 98bbd41..146da33 100644
--- a/src/network_manager.hpp
+++ b/src/network_manager.hpp
@@ -126,6 +126,10 @@
{
reloadPreHooks.push_back(std::move(hook));
}
+ inline void addReloadPostHook(fu2::unique_function<void()>&& hook)
+ {
+ reloadPostHooks.push_back(std::move(hook));
+ }
protected:
/** @brief Persistent sdbusplus DBus bus connection. */
@@ -156,6 +160,7 @@
/** @brief List of hooks to execute during the next reload */
std::vector<fu2::unique_function<void()>> reloadPreHooks;
+ std::vector<fu2::unique_function<void()>> reloadPostHooks;
/** @brief Handles the recipt of an adminstrative state string */
void handleAdminState(std::string_view state, unsigned ifidx);