From nobody@FreeBSD.org  Mon Mar  1 21:41:28 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 7D523106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  1 Mar 2010 21:41:28 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 6C0F68FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  1 Mar 2010 21:41:28 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o21LfS22016380
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 1 Mar 2010 21:41:28 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o21LfSKU016379;
	Mon, 1 Mar 2010 21:41:28 GMT
	(envelope-from nobody)
Message-Id: <201003012141.o21LfSKU016379@www.freebsd.org>
Date: Mon, 1 Mar 2010 21:41:28 GMT
From: andy wilson <wilson.andrew.j@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] /etc/rc.d/named - $named_wait_host needs an upper bound
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         144400
>Category:       conf
>Synopsis:       [patch] /etc/rc.d/named - $named_wait_host needs an upper bound
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dougb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 01 21:50:02 UTC 2010
>Closed-Date:    Sat Mar 13 21:47:37 UTC 2010
>Last-Modified:  Sat Mar 13 21:47:37 UTC 2010
>Originator:     andy wilson
>Release:        8.0-RELEASE-p2
>Organization:
>Environment:
FreeBSD urania.tx.net 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #3: Wed Feb 24 11:30:46 CST 2010     jepp@urania.tx.net:/usr/obj/usr/src/sys/URANIA  i386
>Description:
If you set $named_wait_host to a remote hostname and something is going wrong with the name resolution process for that particular hostname, your system will hang indefinitely. Some services (like ntpd) depend on being able to resolve remote DNS hostnames, but you would still want the system to come up if it is having trouble resolving $named_wait_host.

It would help to have an additional variable that specifies an upper bound for how long /etc/rc.d/named spends attempting to resolve $named_wait_host. That way $named_wait_host can be set to a remote hostname but your system will not be completely dependent on that hostname successfully resolving.



This addition would make it easy to solve problems like the one discussed here:  http://forums.freebsd.org/showthread.php?t=9171

>How-To-Repeat:
Set up rc.conf with the following variables:

ntpd_enable="YES"
named_enable="YES"
named_wait="YES"
named_wait_host="someunresolvablehostname.somenonexistentdomain.com"


Then run: 
/etc/rc.d/named restart
>Fix:
I've attached patches for /etc/rc.d/named and /etc/defaults/rc.conf ; these patches add and document an optional $named_wait_max variable that sets the maximum number of seconds that rc.d/named will wait while trying to resolve $named_wait_host.

Patch attached with submission follows:

--- /etc/rc.d/named.orig	2010-03-01 14:25:19.000000000 -0600
+++ /etc/rc.d/named	2010-03-01 14:26:58.000000000 -0600
@@ -98,11 +98,16 @@
 }
 
 named_poststart () {
+        local count
+
 	make_symlinks
 
+        count=0
+
 	if checkyesno named_wait; then
-		until ${command%/sbin/named}/bin/host $named_wait_host >/dev/null 2>&1; do
+		until ${command%/sbin/named}/bin/host $named_wait_host >/dev/null 2>&1 || ([ $named_wait_max ] && [ $count -gt $named_wait_max ]) ; do
 			echo "	Waiting for nameserver to resolve $named_wait_host"
+                        count=$((${count} + 1))
 			sleep 1
 		done
 	fi


--- /etc/defaults/rc.conf.orig	2010-03-01 15:07:19.000000000 -0600
+++ /etc/defaults/rc.conf	2010-03-01 15:13:24.000000000 -0600
@@ -259,6 +259,9 @@
 named_symlink_enable="YES"	# Symlink the chrooted pid file
 named_wait="NO" 		# Wait for working name service before exiting
 named_wait_host="localhost" 	# Hostname to check if named_wait is enabled
+#named_wait_max="60"            # Maximum number of seconds named_wait will wait
+                                # while attempting to resolve named_wait_host.
+                                # If not set, it will never stop waiting.
 named_auto_forward="NO" 	# Set up forwarders from /etc/resolv.conf
 named_auto_forward_only="NO" 	# Do "forward only" instead of "forward first"
 


>Release-Note:
>Audit-Trail:

From: Andrew Wilson <wilson.andrew.j@gmail.com>
To: bug-followup@FreeBSD.org, wilson.andrew.j@gmail.com
Cc:  
Subject: Re: misc/144400: [patch] /etc/rc.d/named - $named_wait_host needs an 
	upper bound
Date: Mon, 1 Mar 2010 17:30:09 -0600

 I misfiled this; it should have been filed in conf.  Sorry about that.
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Mar 2 00:36:42 UTC 2010 
Responsible-Changed-Why:  
Fix category and assign. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=144400 
Responsible-Changed-From-To: freebsd-rc->dougb 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Mar 13 21:38:46 UTC 2010 
Responsible-Changed-Why:  
dougb has volunteered to look at named bugs. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=144400 
State-Changed-From-To: open->closed 
State-Changed-By: dougb 
State-Changed-When: Sat Mar 13 21:45:11 UTC 2010 
State-Changed-Why:  

I've thought about your PR for a while, and my conclusion is that the 
current setting is doing what it's designed to do. If name resolution 
is critical to the system's function, subverting the _wait option is 
not what we should be doing. If it isn't critical, the user would not 
have set that option in the first place (which defaults to off btw).  

I will keep your PR on record in case this issue resurfaces down the 
road. Meanwhile, thanks for your interest in making FreeBSD better. 


Doug 

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