diff options
author | Ratan Gupta <ratagupt@linux.vnet.ibm.com> | 2018-11-26 20:57:34 +0530 |
---|---|---|
committer | Ratan Gupta <ratagupt@linux.vnet.ibm.com> | 2018-11-30 17:11:46 +0530 |
commit | 895f9e52ff097c5a229dc8ef1fb358a24b9a958f (patch) | |
tree | 576fa50ae0840a6ad405c65b2396f9bb3132c264 | |
parent | 74db23cf883c6eb9d1f10aaff57b9cc167cb0868 (diff) | |
download | phosphor-networkd-895f9e52ff097c5a229dc8ef1fb358a24b9a958f.tar.gz phosphor-networkd-895f9e52ff097c5a229dc8ef1fb358a24b9a958f.zip |
Move the restart systemdunit function to network manager
Change-Id: I647741fc3976ca82c39998a518b1de7be5365e80
Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
-rw-r--r-- | dhcp_configuration.cpp | 8 | ||||
-rw-r--r-- | ethernet_interface.cpp | 4 | ||||
-rw-r--r-- | network_manager.hpp | 14 | ||||
-rw-r--r-- | network_manager_main.cpp | 5 | ||||
-rw-r--r-- | util.hpp | 14 |
5 files changed, 24 insertions, 21 deletions
diff --git a/dhcp_configuration.cpp b/dhcp_configuration.cpp index e492156..7707461 100644 --- a/dhcp_configuration.cpp +++ b/dhcp_configuration.cpp @@ -40,7 +40,7 @@ bool Configuration::hostNameEnabled(bool value) auto name = ConfigIntf::hostNameEnabled(value); manager.writeToConfigurationFile(); - restartSystemdUnit(phosphor::network::networkdService); + manager.restartSystemdUnit(phosphor::network::networkdService); return name; } @@ -54,8 +54,8 @@ bool Configuration::nTPEnabled(bool value) auto ntp = ConfigIntf::nTPEnabled(value); manager.writeToConfigurationFile(); - restartSystemdUnit(phosphor::network::networkdService); - restartSystemdUnit(phosphor::network::timeSynchdService); + manager.restartSystemdUnit(phosphor::network::networkdService); + manager.restartSystemdUnit(phosphor::network::timeSynchdService); return ntp; } @@ -69,7 +69,7 @@ bool Configuration::dNSEnabled(bool value) auto dns = ConfigIntf::dNSEnabled(value); manager.writeToConfigurationFile(); - restartSystemdUnit(phosphor::network::networkdService); + manager.restartSystemdUnit(phosphor::network::networkdService); return dns; } diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp index 893cd4c..f2ad372 100644 --- a/ethernet_interface.cpp +++ b/ethernet_interface.cpp @@ -463,7 +463,7 @@ ServerList EthernetInterface::nTPServers(ServerList servers) writeConfigurationFile(); // timesynchd reads the NTP server configuration from the // network file. - restartSystemdUnit(networkdService); + manager.restartSystemdUnit(networkdService); return ntpServers; } // Need to merge the below function with the code which writes the @@ -701,7 +701,7 @@ std::string EthernetInterface::mACAddress(std::string value) // ip for the changed mac address. if (dHCPEnabled()) { - restartSystemdUnit(networkdService); + manager.restartSystemdUnit(networkdService); } return mac; } diff --git a/network_manager.hpp b/network_manager.hpp index 23eaacb..7a98f9a 100644 --- a/network_manager.hpp +++ b/network_manager.hpp @@ -115,6 +115,20 @@ class Manager : public details::VLANCreateIface /** @brief restart the network timers. */ void restartTimers(); + /** @brief Restart the systemd unit + * @param[in] unit - systemd unit name which needs to be + * restarted. + */ + inline void restartSystemdUnit(const std::string& unit) + { + auto bus = sdbusplus::bus::new_default(); + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "RestartUnit"); + + method.append(unit, "replace"); + bus.call_noreply(method); + } + private: /** @brief Persistent sdbusplus DBus bus connection. */ sdbusplus::bus::bus& bus; diff --git a/network_manager_main.cpp b/network_manager_main.cpp index 2bc203f..dfaeecc 100644 --- a/network_manager_main.cpp +++ b/network_manager_main.cpp @@ -46,7 +46,10 @@ void refreshObjects() /** @brief restart the systemd networkd. */ void restartNetwork() { - restartSystemdUnit("systemd-networkd.service"); + if (manager) + { + manager->restartSystemdUnit("systemd-networkd.service"); + } } void initializeTimers() @@ -121,20 +121,6 @@ std::string getNetworkID(int addressFamily, const std::string& ipaddress, */ IntfAddrMap getInterfaceAddrs(); -/** @brief Restart the systemd unit - * @param[in] unit - systemd unit name which needs to be - * restarted. - */ -inline void restartSystemdUnit(const std::string& unit) -{ - auto bus = sdbusplus::bus::new_default(); - auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, - SYSTEMD_INTERFACE, "RestartUnit"); - - method.append(unit, "replace"); - bus.call_noreply(method); -} - /** @brief Get all the interfaces from the system. * @returns list of interface names. */ |