Skip to content

Commit f18d83f

Browse files
Merge pull request erlang#9543 from diodechain/fix_gethostbyname_gnoring_erl_inetrc OTP-19555
Bugfix: gethostbyname fails to respect ERL_INETRC on first call during initialization on linux
2 parents 8c88e0e + 7c82d2b commit f18d83f

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

lib/kernel/src/inet_config.erl

+30-30
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,6 @@ init() ->
5858
OsType = os:type(),
5959
do_load_resolv(OsType, erl_dist_mode()),
6060

61-
case OsType of
62-
{unix,Type} ->
63-
if Type =:= linux ->
64-
%% It may be the case that the domain name was not set
65-
%% because the hostname was short. But NOW we can look it
66-
%% up and get the long name and the domain name from it.
67-
68-
%% FIXME: The second call to set_hostname will insert
69-
%% a duplicate entry in the search list.
70-
71-
case inet_db:res_option(domain) of
72-
"" ->
73-
case inet:gethostbyname(inet_db:gethostname()) of
74-
{ok,#hostent{h_name = []}} ->
75-
ok;
76-
{ok,#hostent{h_name = HostName}} ->
77-
set_hostname({ok,HostName});
78-
_ ->
79-
ok
80-
end;
81-
_ ->
82-
ok
83-
end;
84-
true -> ok
85-
end,
86-
add_dns_lookup(inet_db:res_option(lookup));
87-
_ ->
88-
ok
89-
end,
90-
9161
%% Read inetrc file, if it exists.
9262
{RcFile,CfgFiles,CfgList} = read_rc(),
9363

@@ -133,6 +103,36 @@ init() ->
133103
_ -> ok
134104
end;
135105
_ -> ok
106+
end,
107+
108+
case OsType of
109+
{unix,Type} ->
110+
if Type =:= linux ->
111+
%% It may be the case that the domain name was not set
112+
%% because the hostname was short. But NOW we can look it
113+
%% up and get the long name and the domain name from it.
114+
115+
%% FIXME: The second call to set_hostname will insert
116+
%% a duplicate entry in the search list.
117+
118+
case inet_db:res_option(domain) of
119+
"" ->
120+
case inet:gethostbyname(inet_db:gethostname()) of
121+
{ok,#hostent{h_name = []}} ->
122+
ok;
123+
{ok,#hostent{h_name = HostName}} ->
124+
set_hostname({ok,HostName});
125+
_ ->
126+
ok
127+
end;
128+
_ ->
129+
ok
130+
end;
131+
true -> ok
132+
end,
133+
add_dns_lookup(inet_db:res_option(lookup));
134+
_ ->
135+
ok
136136
end.
137137

138138

0 commit comments

Comments
 (0)