On Wed, Dec 15, 2010 at 04:08:23PM +0100, Claudio Jeker wrote:
> This made me go nuts for a long time. As soon as you have two interfaces
> running dhclient those two will start fighting over /etc/resolv.conf
> which is realy bad when short lease times are used and one interface is
> not getting new leases.
> 
> This diff extends the dhclient-script in such a way that dhclient will
> only restore the "old" resolv.conf file if it actually is in charge of the
> current file. With this the fighting does not stop but is less
> noticable.
> -- 
> :wq Claudio
> 
> 
> Index: dhclient-script
> ===================================================================
> RCS file: /cvs/src/sbin/dhclient/dhclient-script,v
> retrieving revision 1.17
> diff -u -p -r1.17 dhclient-script
> --- dhclient-script   2 Jun 2010 09:57:16 -0000       1.17
> +++ dhclient-script   4 Nov 2010 11:18:59 -0000
> @@ -111,21 +111,21 @@ add_new_resolv_conf() {
>       # $new_domain_name are provided. As reported in PR#3135, some ISPs
>       # provide only $new_domain_name_servers.
>  
> -     rm -f /etc/resolv.conf.std
> +     rm -f /etc/resolv.conf.$interface.std
>  
>       if [ -n "$new_domain_name" ]; then
> -             echo "search $new_domain_name" >>/etc/resolv.conf.std
> +             echo "search $new_domain_name" >>/etc/resolv.conf.$interface.std
>       fi
>  
>       if [ -n "$new_domain_name_servers" ]; then
>               for nameserver in $new_domain_name_servers; do
> -                     echo "nameserver $nameserver" >>/etc/resolv.conf.std
> +                     echo "nameserver $nameserver" 
> >>/etc/resolv.conf.$interface.std
>               done
>       fi
>  
> -     if [ -f /etc/resolv.conf.std ]; then
> +     if [ -f /etc/resolv.conf.$interface.std ]; then
>               if [ -f /etc/resolv.conf.tail ]; then
> -                     cat /etc/resolv.conf.tail >>/etc/resolv.conf.std
> +                     cat /etc/resolv.conf.tail 
> >>/etc/resolv.conf.$interface.std
>               fi
>  
>               # In case (e.g. during OpenBSD installs) /etc/resolv.conf
> @@ -133,10 +133,9 @@ add_new_resolv_conf() {
>               # the new data in the correct location.
>  
>               if [ -f /etc/resolv.conf ]; then
> -                     cat /etc/resolv.conf > /etc/resolv.conf.save
> +                     cat /etc/resolv.conf > /etc/resolv.conf.$interface.save
>               fi
> -             cat /etc/resolv.conf.std > /etc/resolv.conf
> -             rm -f /etc/resolv.conf.std
> +             cat /etc/resolv.conf.$interface.std > /etc/resolv.conf
>  
>               # Try to ensure correct ownership and permissions.
>               chown -RL root:wheel /etc/resolv.conf
> @@ -152,21 +151,21 @@ ip6_add_new_resolv_conf() {
>       # Create resolv.conf when either $new_dhcp6_name_servers or
>       # $new_dhcp6_domain_search are provided.
>  
> -     rm -f /etc/resolv.conf.std6
> +     rm -f /etc/resolv.conf.$interface.std6
>  
>       if [ -n "$new_dhcp6_domain_search" ]; then
> -             echo "search $new_dhcp6_domain_search" >>/etc/resolv.conf.std6
> +             echo "search $new_dhcp6_domain_search" 
> >>/etc/resolv.conf.$interface.std6
>       fi
>  
>       if [ -n "$new_dhcp6_name_servers" ]; then
>               for nameserver in $new_dhcp6_name_servers; do
> -                     echo "nameserver $nameserver" >>/etc/resolv.conf.std6
> +                     echo "nameserver $nameserver" 
> >>/etc/resolv.conf.$interface.std6
>               done
>       fi
>  
> -     if [ -f /etc/resolv.conf.std6 ]; then
> +     if [ -f /etc/resolv.conf.$interface.std6 ]; then
>               if [ -f /etc/resolv.conf.tail ]; then
> -                     cat /etc/resolv.conf.tail >>/etc/resolv.conf.std6
> +                     cat /etc/resolv.conf.tail 
> >>/etc/resolv.conf.$interface.std6
>               fi
>  
>               # In case (e.g. during OpenBSD installs) /etc/resolv.conf
> @@ -174,10 +173,9 @@ ip6_add_new_resolv_conf() {
>               # the new data in the correct location.
>  
>               if [ -f /etc/resolv.conf ]; then
> -                     cat /etc/resolv.conf > /etc/resolv.conf.save
> +                     cat /etc/resolv.conf > /etc/resolv.conf.$interface.save
>               fi
> -             cat /etc/resolv.conf.std6 > /etc/resolv.conf
> -             rm -f /etc/resolv.conf.std6
> +             cat /etc/resolv.conf.$interface.std6 > /etc/resolv.conf
>  
>               # Try to ensure correct ownership and permissions.
>               chown -RL root:wheel /etc/resolv.conf
> @@ -256,8 +254,13 @@ EXPIRE|FAIL)
>       fi
>       # XXX Why add alias we just deleted above?
>       add_new_alias
> -     if [ -f /etc/resolv.conf.save ]; then
> -             cat /etc/resolv.conf.save > /etc/resolv.conf
> +     if [ -f /etc/resolv.conf.$interface.std ]; then
> +             cmp -s /etc/resolv.conf /etc/resolv.conf.$interface.std
> +             if [ $? -eq 0 -a -f /etc/resolv.conf.$interface.save ]; then
> +                     cat /etc/resolv.conf.$interface.save > /etc/resolv.conf
> +             fi
> +             rm -f /etc/resolv.conf.$interface.save
> +             rm -f /etc/resolv.conf.$interface.std
>       fi
>       ;;
> 

This looks like a step forward, and worth trying out. ok k...@.

.... Ken

Reply via email to