ibc / em-udns

An async DNS resolver for EventMachine based on the udns C library
http://ibc.github.com/em-udns/
GNU Lesser General Public License v2.1
37 stars 12 forks source link

Passing the nameserver(s) doesn't take preference over /etc/resolv.conf #4

Closed ibc closed 13 years ago

ibc commented 13 years ago

It seems that udns always takes the list of nameservers from /etc/resolv.conf, regardless of the existance of the NAMESERVERS enviroment variable. Extracted from udns documentation:

When initializing resolver context, the library uses information from system file /etc/resolv.conf (see resolv.conf(5)), consults environment variables $LOCALDOMAIN, $DNSCACHEIP, $NAMESERVERS and $RES_OPTIONS, and local host name to obtain list of local nameservers, domain name search list and various resolver options.

So passing an IP (a nameserver) to EM::Udns::Resolver.new doesn't work. Must be investigated and the documentation fixed after that.

ibc commented 13 years ago

Michael Tokarev probed that it can work if the enviroment variable NAMESERVERS is set:

The only trap that comes to mind is that you didn't export NAMESERVERS variable so it's not available in subprocesses.

Check this:

NAMESERVERS=127.0.0.2 dnsget -vv foo.bar

it will tell where it is sending queries to (if nothing is listening on 127.0.0.2 it will just time out).

NAMESERVERS=127.0.0.2; dnsget -vv foo.bar

(note the semicolon) -- this will change nothing, dnsget will use regular nameservers listed in /etc/resolv.conf. And this:

export NAMESERVERS=127.0.0.2; dnsget -vv foo.bar

will use 127.0.0.1 again.

So it seems that the way I set the enviroment NAMESERVERS variable:

ENV["NAMESERVERS"] = .....

is not valid as udns doesn't see it as an enviroment variable. I must fix that.

ibc commented 13 years ago

I must set ENV["NAMESERVERS"] before initializing the EM::Udns::Resolver instance, as udns is loaded when allocating the class (which happens before "initialize" method). So I must create a new class method for it.

ibc commented 13 years ago

Fixed by commit https://github.com/ibc/em-udns/commit/4e1a1c26faf3a8b40d6c5adcee5e61fbd7211408