resolver ... again
Klacke
klacke@REDACTED
Fri Jun 6 13:09:35 CEST 2003
Howdy,
The code in inet_config.erl is not quite right.
On linux, the code in the inet_config:init/0
reads /etc/hosts.conf (only)
The glibc resolver reads both the /etc/host.conf aswell
as /etc/nsswitch.conf
A very old system
[root@REDACTED /root]# cat /etc/redhat-release
Red Hat Linux release 6.2 (Zoot)
[root@REDACTED /root]# strace ping -c 1 www.erlang.org 2>&1 | grep '/etc/.*.conf'
open("/etc/resolv.conf", O_RDONLY) = 4
open("/etc/nsswitch.conf", O_RDONLY) = 4
read(4, "#\n# /etc/nsswitch.conf\n#\n# An ex"..., 4096) = 1767
open("/etc/host.conf", O_RDONLY) = 4
Slightly newer ....
# cat /etc/redhat-release
Red Hat Linux release 7.3 (Valhalla)
# strace ping -c 1 www.erlang.org 2>&1 | grep '/etc/.*.conf'
open("/etc/resolv.conf", O_RDONLY) = 3
open("/etc/nsswitch.conf", O_RDONLY) = 3
read(3, "#\n# /etc/nsswitch.conf\n#\n# An ex"..., 4096) = 1682
open("/etc/host.conf", O_RDONLY) = 3
And then to the boring part:
tita root # uname -a
Linux tita 2.4.20-gentoo-r5-1 #1 SMP Wed Jun 4 16:51:01 CEST 2003 i686 Intel(R) Pentium(R) 4 CPU 2.20GHz GenuineIntel GNU/Linux
tita root # strace ping -c 1 www.erlang.org 2>&1 | grep '/etc/.*.conf'
open("/etc/nsswitch.conf", O_RDONLY) = 3
read(3, "# /etc/nsswitch.conf:\n# $Header:"..., 4096) = 498
open("/etc/resolv.conf", O_RDONLY) = 4
open("/etc/host.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
Gentoo doesn't have the /etc/host.conf file.
This does indeed make sence, having two _different_ files
controling the behaviour of the resolver is broken.
The erlang code _only_ reads the /etc/host.conf file, in order to
a) work on gentoo
b) be more glibc like
We should at least also read the /etc/nsswitch.conf file.
Preferable we should first read /etc/nsswitch.conf and then
if that fails read /etc/host.conf
The /etc/hosts.conf file is an old BSDism and I think that
very few tools (except OTP then :-) works with that file.
Here's a possible patch, reading /etc/hosts.conf first and then
/etc/nsswitch.conf
But as I wrote, even better would be to read nsswitch before hosts.
People are probably more accustomed to changing the nsswitch
file than the host file.
Enjoy.
/klacke
--
Claes Wikstrom -- Caps lock is nowhere and
Alteon WebSystems -- everything is under control
http://www.bluetail.com/~klacke
cellphone: +46 70 2097763
-------------- next part --------------
Index: inet_config.erl
===================================================================
RCS file: /home/share/erlang/cvsroot/otp/lib/kernel/src/inet_config.erl,v
retrieving revision 1.5
diff -c -b -r1.5 inet_config.erl
*** inet_config.erl 25 Feb 2003 13:37:22 -0000 1.5
--- inet_config.erl 6 Jun 2003 11:00:35 -0000
***************
*** 82,88 ****
'bsd/os' ->
load_resolv(filename:join(Etc,"irs.conf"), host_conf_bsdos);
linux ->
! load_resolv(filename:join(Etc,"host.conf"),host_conf_linux),
% It may be the case that the domain name was not set
% because the hostname was short. But we can now look it
--- 82,93 ----
'bsd/os' ->
load_resolv(filename:join(Etc,"irs.conf"), host_conf_bsdos);
linux ->
! case load_resolv(filename:join(Etc,"host.conf"),host_conf_linux) of
! ok ->
! ok;
! _Other ->
! load_resolv(filename:join(Etc,"nsswitch.conf"), nsswitch_conf)
! end,
% It may be the case that the domain name was not set
% because the hostname was short. But we can now look it
***************
*** 296,305 ****
case apply(inet_parse, Func, [File,{chars,Bin}]) of
{ok, Ls} -> inet_db:add_rc_list(Ls);
{error, Reason} ->
! error("parse error in file ~s: ~p", [File, Reason])
end;
Error ->
! warning("file not found ~s~n", [File])
end.
%%
--- 301,312 ----
case apply(inet_parse, Func, [File,{chars,Bin}]) of
{ok, Ls} -> inet_db:add_rc_list(Ls);
{error, Reason} ->
! error("parse error in file ~s: ~p", [File, Reason]),
! {error, Reason}
end;
Error ->
! warning("file not found ~s~n", [File]),
! Error
end.
%%
More information about the erlang-bugs
mailing list