Remove nameserver 127.0.0.1 line rather then dumping resolv.conf

We have a bug report complaining about docker dumping the contents of the
hosts resolv.conf if it container 127.0.0.1.  They asked that instead
of dropping the file altogether, that we just remove the line.

This patch removes the 127.0.0.1 lines, if they exist and then
checks if any nameserver lines exist.

Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)


On 09/23/2014 05:37 PM, Erik Hollensbe wrote:
>
> In utils/utils.go:
>
> > @@ -332,6 +333,17 @@ func CheckLocalDns(resolvConf []byte) bool {
> >  	return true
> >  }
> >  
> > +var (
> > +	localhostRx = regexp.MustCompile("nameserver\\s+127.*\\n?")
> Hi Dan, please try: http://play.golang.org/p/qxRecxvlVU Which should
> match a newline if it exists, and will only cover the same line. It
> will also replace all the 127.x.x.x entries.
> … <#>
> On Sep 23, 2014, at 2:17 PM, rhatdan <notifications@github.com> wrote:
> In utils/utils.go: > @@ -332,6 +333,17 @@ func
> CheckLocalDns(resolvConf []byte) bool { > return true > } > > +var ( >
> + localhostRx = regexp.MustCompile("nameserver\\s+127.*\\n?") If you
> have a 127.0.0.1 line with no \n — Reply to this email directly or
> view it on GitHub.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/docker/docker/pull/8047/files#r17941205>.
>
Here is my test program.

http://play.golang.org/p/c89Q_lBKYk

My problem is the case where nameserver 127.0.0.1 is the last line in
the resolv.conf without a \n.
We end up with a blank line.

My test program is just comparing a good outcome to all possible
outcomes, but if we want the \n at the end, then I can add this to the
test.  And be done with this.