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: "H.J. Lu" X-Patchwork-Id: 701637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tV62s06Yyz9vFX for ; Fri, 2 Dec 2016 05:56:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="tPfH7mpu"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; q=dns; s=default; b=vLgncLFzV+MlM6c5 9hCM8nLPcq9E3Cro17ONX660COe2VpaEwd4zNHb5dl5w9gRGF8e4i1SN8GFrvNMO WtEgsyls2DKNLD8Bu59obfvd2LFuzerqTXxRpcFSK9pG3P5yt29gXaJkORQUoumY 8eGQ+eZC0SBolfImWSUPKmVW9KI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; s=default; bh=0IY9QEGHs13C2EHuNFtXjJ DOPEo=; b=tPfH7mpuTDKe/34lRNvCkMD2vzE6TIht09VJ2ao72GI17DMMgBjeSv Eb6wacInV842w5enrUOy9vbCxpopCYRc/tj+dCFne6mwDOSA8ytcda1J8goICXRU FyEn6RuKwgaouRKtNbJfaUY+ptwcSoqm7j+2aMQFqAvXmOtH+t05M= 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) {