From 770c581cbe87706d2879025dfd3ea900933ed5e1 Mon Sep 17 00:00:00 2001 From: Michal Ptaszek Date: Thu, 28 Jan 2016 15:09:16 -0600 Subject: Allow to refresh resolver settings on startup After the VM time changes inet_db:times/0 instead of returning number of seconds since 1970, returns number of seconds since the VM start. As a result, if inet_res:lookup is called right after the system start, the condition for re-reading /etc/resolv.conf will not be met (time difference between last access: 0, and the value returned from inet_db:times/0 -> [0-5) is lower than 5 seconds) and no nameservers will be used. This patch allows /etc/resolv.conf to be read immediately after the system is started. --- lib/kernel/src/inet_db.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/kernel/src/inet_db.erl b/lib/kernel/src/inet_db.erl index 108a803610..7278ec460d 100644 --- a/lib/kernel/src/inet_db.erl +++ b/lib/kernel/src/inet_db.erl @@ -514,7 +514,8 @@ res_update(Tag, TagTm, TagInfo, TagSetTm, SetFun) -> undefined -> ok; TM -> case times() of - Now when Now >= TM + ?RES_FILE_UPDATE_TM -> + Now when Now >= TM + ?RES_FILE_UPDATE_TM; + (TM =:= 0 andalso Now < ?RES_FILE_UPDATE_TM) -> case db_get(Tag) of undefined -> SetFun(""); -- cgit v1.2.3 From e8f83e476ffc47d63696ce8a11e71ab6213809c2 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 5 Apr 2016 16:12:38 +0200 Subject: Fix start timestamp instead of time check Verify with: erl -noshell -eval 'io:write(inet_res:lookup("localhost",in,a)),io:nl(),init:stop().' Prints: [{127,0,0,1}] Without this correction you will get [] on a hostname that works later after system start. --- lib/kernel/src/inet_db.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/kernel/src/inet_db.erl b/lib/kernel/src/inet_db.erl index 7278ec460d..465cec1b45 100644 --- a/lib/kernel/src/inet_db.erl +++ b/lib/kernel/src/inet_db.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2013. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -514,8 +514,7 @@ res_update(Tag, TagTm, TagInfo, TagSetTm, SetFun) -> undefined -> ok; TM -> case times() of - Now when Now >= TM + ?RES_FILE_UPDATE_TM; - (TM =:= 0 andalso Now < ?RES_FILE_UPDATE_TM) -> + Now when Now >= TM + ?RES_FILE_UPDATE_TM -> case db_get(Tag) of undefined -> SetFun(""); @@ -1207,7 +1206,8 @@ handle_set_file(Option, Fname, TagTm, TagInfo, ParseFun, From, File = filename:flatten(Fname), ets:insert(Db, {res_optname(Option), File}), ets:insert(Db, {TagInfo, undefined}), - ets:insert(Db, {TagTm, 0}), + TimeZero = - (?RES_FILE_UPDATE_TM + 1), % Early enough + ets:insert(Db, {TagTm, TimeZero}), {reply,ok,State}; true -> File = filename:flatten(Fname), -- cgit v1.2.3