From: Roy Marples Date: Tue, 12 Aug 2008 23:32:18 +0000 (+0000) Subject: Remove the signature variable - each hook makes it's own. X-Git-Tag: v4.0.2~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=edffba160425bf6b652f97b5515fe3065768fe4e;p=thirdparty%2Fdhcpcd.git Remove the signature variable - each hook makes it's own. ntp.conf now preserves existing server entries and cleans stale dhcpcd entries --- diff --git a/dhcpcd-hooks/20-resolv.conf b/dhcpcd-hooks/20-resolv.conf index 2cd2939c..b377a67b 100644 --- a/dhcpcd-hooks/20-resolv.conf +++ b/dhcpcd-hooks/20-resolv.conf @@ -8,7 +8,7 @@ make_resolv_conf() -z "${new_domain_search}" ]; then return 0 fi - local x= conf="# ${signature}\n" + local x= conf="# Generated by dhcpcd for interface ${interface}\n" if [ -n "${new_domain_search}" ]; then conf="${conf}search ${new_domain_search}\n" elif [ -n "${new_domain_name}" ]; then diff --git a/dhcpcd-hooks/50-ntp.conf b/dhcpcd-hooks/50-ntp.conf index 6cc1b670..818b4dd4 100644 --- a/dhcpcd-hooks/50-ntp.conf +++ b/dhcpcd-hooks/50-ntp.conf @@ -10,28 +10,44 @@ elif [ -x /usr/local/etc/rc.d/ntpd ]; then ntpd_restart_cmd="/usr/local/etc/rc.d/ntpd restart" fi -make_ntp_conf() +do_ntp_conf() { - [ -z "${new_ntp_servers}" ] && return 0 - local cf=/etc/ntp.conf."${interface}" x= + local cf=/etc/ntp.conf."${interface}" x= m1= m2= + local sig="# Generated by dhcpcd for interface" + local sig_end="# End of dhcpcd content for interface" - grep -v "\(^[ \t]*server[ \t]*\|${signature}\)" /etc/ntp.conf > "${cf}" - echo "# ${signature}" >> "${cf}" - for x in ${new_ntp_servers}; do - echo "server ${x}" >> "${cf}" - done - save_conf /etc/ntp.conf - mv -f "${cf}" /etc/ntp.conf - [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd} -} - -restore_ntp_conf() -{ - restore_conf /etc/ntp.conf || return 0 - [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd} + if [ -f /etc/ntp.conf ]; then + # Remove our old entry + m1="^${sig} ${interface}$" + m2="^${sig_end} ${interface}$" + sed "/${m1}/,/${m2}/d" /etc/ntp.conf > "${cf}" + # Remove stale entries + m1="^${sig} " + for x in $(sed -n "s/${m1}//p" "${cf}"); do + if [ ! -s /var/run/dhcpcd-${x}.pid ]; then + m1="^${sig} ${x}$" + m2="^${sig_end} ${x}$" + sed "/${m1}/,/${m2}/d" "${cf}" >"${cf}".tmp + mv -f "${cf}".tmp "${cf}" + fi + done + else + rm -f "${cf}" + fi + if [ "$1" = "add" -a -n "${new_ntp_servers}" ]; then + echo "${sig} ${interface}" >> "${cf}" + for x in ${new_ntp_servers}; do + echo "server ${x}" >> "${cf}" + done + echo "${sig_end} ${interface}" >> "${cf}" + fi + if [ -f "${cf}" ]; then + mv -f "${cf}" /etc/ntp.conf + [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd} + fi } case "${reason}" in -BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_ntp_conf;; -EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_ntp_conf;; +BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) do_ntp_conf add;; +EXPIRE|FAIL|IPV4LL|RELEASE|STOP) do_ntp_conf del;; esac diff --git a/dhcpcd-hooks/50-yp.conf b/dhcpcd-hooks/50-yp.conf index 25b40170..a82bd5d7 100644 --- a/dhcpcd-hooks/50-yp.conf +++ b/dhcpcd-hooks/50-yp.conf @@ -10,7 +10,7 @@ make_yp_conf() { [ -z "${new_nis_domain}" -a -z "${new_nis_servers}" ] && return 0 local cf=/etc/yp.conf."${interface}" prefix= x= pid= - echo "# ${signature}" > "${cf}" + echo "# Generated by dhcpcd for interface ${interface}" > "${cf}" if [ -n "${new_nis_domain}" ]; then domainname "${new_nis_domain}" if [ -n "${new_nis_servers}" ]; then diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in index a4a55e27..94d9dfc4 100644 --- a/dhcpcd-run-hooks.in +++ b/dhcpcd-run-hooks.in @@ -2,7 +2,6 @@ # dhcpcd client configuration script # Handy functions for our hooks to use -signature="Generated by dhcpcd for ${interface}" save_conf() { if [ -f "$1" ]; then