From patchwork Thu Dec 1 18:56:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lu, Hongjiu" X-Patchwork-Id: 18106 Received: (qmail 748 invoked by alias); 1 Dec 2016 18:56:46 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 692 invoked by uid 89); 1 Dec 2016 18:56:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:1399, inh, arpa, 23, 7 X-HELO: mga14.intel.com X-ExtLoop1: 1 Date: Thu, 1 Dec 2016 10:56:41 -0800 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] [BZ #20900] Call __res_vinit if _PATH_RESCONF is changed Message-ID: <20161201185641.GA15507@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) The content of _PATH_RESCONF may change over time with DHCP. __res_maybe_init should check if _PATH_RESCONF is changed. Otherwise a long-running process will get wrong DNS results if _PATH_RESCONF is changed by DHCP. Any comments? H.J. --- [BZ #20900] * resolv/res_libc.c: Include . (__res_maybe_init): Call __res_vinit if _PATH_RESCONF has been changed since the last time. --- resolv/res_libc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/resolv/res_libc.c b/resolv/res_libc.c index a4b376f..47b2d42 100644 --- a/resolv/res_libc.c +++ b/resolv/res_libc.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -97,6 +98,21 @@ __res_maybe_init (res_state resp, int preinit) if (resp->nscount > 0) __res_iclose (resp, true); return __res_vinit (resp, 1); + } else { + struct stat buf; + + /* Call __res_vinit if _PATH_RESCONF has been + changed since the last time. */ + if (stat (_PATH_RESCONF, &buf) == 0) { + static struct timespec mtime; + if (mtime.tv_sec != buf.st_mtim.tv_sec + || mtime.tv_nsec != buf.st_mtim.tv_nsec) { + mtime = buf.st_mtim; + if (resp->nscount > 0) + __res_iclose (resp, true); + return __res_vinit (resp, 1); + } + } } return 0; } else if (preinit) {