]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Remove the signature variable - each hook makes it's own.
authorRoy Marples <roy@marples.name>
Tue, 12 Aug 2008 23:32:18 +0000 (23:32 +0000)
committerRoy Marples <roy@marples.name>
Tue, 12 Aug 2008 23:32:18 +0000 (23:32 +0000)
ntp.conf now preserves existing server entries and cleans stale dhcpcd
entries

dhcpcd-hooks/20-resolv.conf
dhcpcd-hooks/50-ntp.conf
dhcpcd-hooks/50-yp.conf
dhcpcd-run-hooks.in

index 2cd2939c76662e027074967b7ba90b748fd39c4b..b377a67bf07c01f0332cc494b59929c7522192df 100644 (file)
@@ -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
index 6cc1b67090d41501294b1b392666d8081ba02cfb..818b4dd4c141da0d35ec4a04b76b418fbc6b962b 100644 (file)
@@ -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
index 25b40170f54fce8c55e3cd516560b50fce8f2cb9..a82bd5d7c2407302a08529c3e0c22803a32bbf09 100644 (file)
@@ -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
index a4a55e27503970c2ec6c07d60b454cae7beee71b..94d9dfc48e80baeb75e4327ee5eebb81ead6c331 100644 (file)
@@ -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