From dafc459f23f3c6ac6af73e1789788e0fd24c5866 Mon Sep 17 00:00:00 2001 From: Arjuna Del Toso Date: Thu, 20 Dec 2018 16:06:11 -0800 Subject: [PATCH] [PATCH] Only restart resolved on changes in dhclient enter hook This prevents spurious restarts of resolved on rebounds when the addresses did not change. Tested on $ uname -a Linux ip-172-31-14-255 4.15.0-42-generic #45-Ubuntu SMP Thu Nov 15 19:32:57 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionic $ dhclient --version isc-dhclient-4.3.5 $ systemd --version systemd 237 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid $ bash --version GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu) LP: #1805183 --- debian/extra/dhclient-enter-resolved-hook | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/debian/extra/dhclient-enter-resolved-hook b/debian/extra/dhclient-enter-resolved-hook index b504f5b..bf37494 100755 --- a/debian/extra/dhclient-enter-resolved-hook +++ b/debian/extra/dhclient-enter-resolved-hook @@ -28,6 +28,9 @@ if [ -x /lib/systemd/systemd-resolved ] ; then fi statedir="/run/systemd/resolved.conf.d" mkdir -p $statedir + + oldstate="$(mktemp)" + md5sum $statedir/isc-dhcp-v4-$interface.conf $statedir/isc-dhcp-v6-$interface.conf > $oldstate 2>&1 if [ -n "$new_domain_name_servers" ] ; then cat <$statedir/isc-dhcp-v4-$interface.conf [Resolve] @@ -50,7 +53,15 @@ Domains=$new_dhcp6_domain_search EOF fi fi - systemctl try-reload-or-restart systemd-resolved.service + + newstate="$(mktemp)" + md5sum $statedir/isc-dhcp-v4-$interface.conf $statedir/isc-dhcp-v6-$interface.conf > $newstate 2>&1 + if ! cmp --quiet $oldstate $newstate; then + systemctl try-reload-or-restart systemd-resolved.service + fi + + rm $oldstate + rm $newstate } ;; -- 2.7.4