From nobody@www.freebsd.org  Fri May 31 13:13:33 2002
Return-Path: <nobody@www.freebsd.org>
Received: from nwww.freebsd.org (www.FreeBSD.org [216.136.204.117])
	by hub.freebsd.org (Postfix) with ESMTP id 899E537B406
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 31 May 2002 13:13:32 -0700 (PDT)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by nwww.freebsd.org (8.12.2/8.12.2) with ESMTP id g4VKDWhG072421
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 31 May 2002 13:13:32 -0700 (PDT)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.2/8.12.2/Submit) id g4VKDWHE072420;
	Fri, 31 May 2002 13:13:32 -0700 (PDT)
Message-Id: <200205312013.g4VKDWHE072420@www.freebsd.org>
Date: Fri, 31 May 2002 13:13:32 -0700 (PDT)
From: C J Michaels <cjm2@earthling.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: dhclient infinite loop on ro /etc/resolv.conf
X-Send-Pr-Version: www-1.0

>Number:         38778
>Category:       bin
>Synopsis:       dhclient infinite loop on ro /etc/resolv.conf
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    mbr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 31 13:20:02 PDT 2002
>Closed-Date:    Mon Jul 28 15:29:34 PDT 2003
>Last-Modified:  Mon Jul 28 15:29:34 PDT 2003
>Originator:     C J Michaels
>Release:        4.6-RC
>Organization:
n/a
>Environment:
FreeBSD cartman.lan.27in.tv 4.6-RC FreeBSD 4.6-RC #11: Mon May 27 20:45:02 EDT 2002     root@:/usr/local/obj/usr/local/src/sys/CARTMAN  i386
>Description:
If dhclient is unable to write a new /etc/resolv.conf when it obtains a new lease, it will loop and immediately request a new DHCP lease.  This results in an infinte loop where dhclient requests a new lease ~ every 5 seconds.

Also, at no time does dhclient print an error message to advise you of what's going on.

This is a problem for anyone who either has /etc/ mounted read only, or if /etc/resolv.conf is immutable.

Note: this problems seems to have appears around the time of 4.6-RC as my last 4.5-STABLE build didn't have this problem.
>How-To-Repeat:
chflags schg /etc/resolv.conf; /sbin/dhclient ed0
>Fix:

>Release-Note:
>Audit-Trail:

From: Volker Stolz <stolz@i2.informatik.rwth-aachen.de>
To: freebsd-gnats-submit@FreeBSD.org, cjm2@earthling.net
Cc:  
Subject: Re: bin/38778: dhclient infinite loop on ro /etc/resolv.conf
Date: Wed, 12 Jun 2002 10:24:13 +0200

 This is really fun! If you set resolv.conf immutable,
 the dhclient-script will be *terminated* on issuing the
 echo ... >/etc/resolv.conf, i.e. no further instructions
 will be executed. The dhclient thinks the script failed
 (well, it did), and tries another time :-/
 
 It's also worth noting that setting 'schg' is NOT the
 same as making /etc/resolv.conf ro; mounting /etc ro
 should be yet another case.
 
 Here's how to reproduce this w/o using dhclient:
 
 1) Create a small shell-script test.sh:
 echo `date` >>foo
 echo "done!"
 
 2) Create 'foo' and set immutable:
 touch foo
 chflags schg foo
 
 3) Run test.sh and notice how the 2nd echo is never
 executed:
 
 bsd# sh test.sh
 test.sh: cannot create foo: error 1
 
 How do I trap this event in sh? Using
 	eval 'echo ... >>foo'
 doesn't work, either. Using
 	eval 'echo ... >>foo &'
 works in a way, but isn't an option in dhsclient-script
 for worst-case scheduling...
 -- 
 "Gemischte Materialien // Frher: Restmll"
 Aufschrift auf einem Container, Informatik-Parkplatz

From: Giorgos Keramidas <keramida@FreeBSD.org>
To: Volker Stolz <stolz@i2.informatik.rwth-aachen.de>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/38778: dhclient infinite loop on ro /etc/resolv.conf
Date: Fri, 14 Jun 2002 23:30:49 +0300

 On 2002-06-12 23:50 -0700, Volker Stolz wrote:
 > Here's how to reproduce this w/o using dhclient:
 
 I can't reproduce this in my -CURRENT installation (rebuilt Jun 9).
 
 > 1) Create a small shell-script test.sh:
 > echo `date` >>foo
 > echo "done!"
 
 	23:26 [root@hades /tmp]# cat > test.sh
 	date >> foo
 	echo 'done.'
 
 > 2) Create 'foo' and set immutable:
 > touch foo
 > chflags schg foo
 
 	23:26 [root@hades /tmp]# touch foo
 	23:26 [root@hades /tmp]# chflags schg foo
 	23:26 [root@hades /tmp]# ls -lo foo
 	-rw-r--r--  1 root  wheel  schg 0 Jun 14 23:26 foo
 
 > 3) Run test.sh and notice how the 2nd echo is never
 > executed:
 >
 > bsd# sh test.sh
 > test.sh: cannot create foo: error 1
 
 	23:26 [root@hades /tmp]# sh test.sh
 	test.sh: cannot create foo: error 1
 	done.
 
 There is also a very easy way to check for failure of the first
 command.  See test2.sh shown below:
 
 	23:29 [root@hades /tmp]# cat test2.sh
 	date >> foo || { echo 'date(1) failed' ; exit 1 ; }
 	echo 'done.'
 	23:29 [root@hades /tmp]# sh test2.sh
 	test2.sh: cannot create foo: error 1
 	date(1) failed
 
 - Giorgos
 

From: Jonathan Chen <jon@FreeBSD.org>
To: Volker Stolz <stolz@i2.informatik.rwth-aachen.de>
Cc: freebsd-gnats-submit@FreeBSD.org, cjm2@earthling.net
Subject: Re: bin/38778: dhclient infinite loop on ro /etc/resolv.conf
Date: Fri, 5 Jul 2002 14:40:57 -0400

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 On Wed, Jun 12, 2002 at 10:24:13AM +0200, Volker Stolz wrote:
 >  This is really fun! If you set resolv.conf immutable,
 >  the dhclient-script will be *terminated* on issuing the
 >  echo ... >/etc/resolv.conf, i.e. no further instructions
 >  will be executed. The dhclient thinks the script failed
 >  (well, it did), and tries another time :-/
 >  
 >  It's also worth noting that setting 'schg' is NOT the
 >  same as making /etc/resolv.conf ro; mounting /etc ro
 >  should be yet another case.
 >  
 >  Here's how to reproduce this w/o using dhclient:
 >  
 >  1) Create a small shell-script test.sh:
 >  echo `date` >>foo
 >  echo "done!"
 [snip]
 
 This is because /bin/sh likes to give up completely whenever an internal 
 command redirection fails.  I've been bitten by this more than once before.  
 The error could easily be trapped by enclosing the offending commands in 
 (), ie ( echo `date` >> foo ).  This make /bin/sh fork a new instance and 
 do the redirection there.  This will also conveniently return a non-zero 
 error code on failure.
 
 Please try the below patch and let me know if it works:  (From -CURRENT, 
 some manual merging may be necessary if you're running an older -STABLE)
 
 Index: dhclient-script
 ===================================================================
 RCS file: /export/ncvs/src/contrib/isc-dhcp/client/scripts/dhclient-script,v
 retrieving revision 1.20
 diff -u -r1.20 dhclient-script
 - --- dhclient-script	19 Feb 2002 12:10:40 -0000	1.20
 +++ dhclient-script	5 Jul 2002 18:05:06 -0000
 @@ -10,10 +10,15 @@
  
  make_resolv_conf() {
    if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then
 - -    echo search $new_domain_name >/etc/resolv.conf
 - -    for nameserver in $new_domain_name_servers; do
 - -      echo nameserver $nameserver >>/etc/resolv.conf
 - -    done
 +    ( echo search $new_domain_name >/etc/resolv.conf )
 +    exit_status=$?
 +    if [ $exit_status -ne 0 ]; then
 +      $LOGGER "WARNING: Unable to update resolv.conf: Error $exit_status"
 +    else
 +      for nameserver in $new_domain_name_servers; do
 + 	( echo nameserver $nameserver >>/etc/resolv.conf )
 +      done
 +    fi
    fi
  }
  
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.6 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iEYEARECAAYFAj0l6DgACgkQwvyGqiU5Ros4iwCdFGxz/r4D3Cu1fG1NEYlo4edy
 8YsAoPIygVftjfb2+barhe3cOzbRNO/R
 =q0mB
 -----END PGP SIGNATURE-----
Responsible-Changed-From-To: freebsd-bugs->mbr 
Responsible-Changed-By: mbr 
Responsible-Changed-When: Mon Feb 10 01:49:38 PST 2003 
Responsible-Changed-Why:  
I'll take care about this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=38778 

From: Stijn Hoop <stijn@win.tue.nl>
To: freebsd-gnats-submit@FreeBSD.org, cjm%32@earthling.net
Cc:  
Subject: Re: bin/38778: dhclient infinite loop on ro /etc/resolv.conf
Date: Tue, 18 Feb 2003 16:22:06 +0100

 For people that need a workaround to specify their own options in
 /etc/resolv.conf, eg their nameserver, instead of the DHCP-supplied values,
 check out the 'supersede' option of dhclient.conf. See the manpage for
 details.
 
 This has nothing to do with the fact that dhclient should or should not be
 made to respect a read-only resolv.conf, it only represents a workaround for
 the common case of wanting to have one.
 
 --Stijn
 
 -- 
 This sentence contradicts itself -- no actually it doesn't.
 		-- Hofstadter
State-Changed-From-To: open->analyzed 
State-Changed-By: mbr 
State-Changed-When: Sat Apr 26 16:33:40 PDT 2003 
State-Changed-Why:  
Committed to the ISC repo. The PR will be closed after 
the next dhclient import is done. Thank you for the fix 
btw ! 

Martin 

http://www.freebsd.org/cgi/query-pr.cgi?pr=38778 
State-Changed-From-To: analyzed->closed 
State-Changed-By: mbr 
State-Changed-When: Mon Jul 28 15:29:14 PDT 2003 
State-Changed-Why:  
Fixed in CURRENT. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=38778 
>Unformatted:
