From patchwork Thu Dec 1 19:29:16 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: 18110 Received: (qmail 50247 invoked by alias); 1 Dec 2016 19:29:29 -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 50219 invoked by uid 89); 1 Dec 2016 19:29:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=hongjiu.lu@intel.com, hongjiuluintelcom, Hx-languages-length:1345 X-HELO: mail-qt0-f195.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=MdC0DwgvKCmcvC/+7ugXAKP8JQoeevW2hbTxU0XHLMo=; b=S32lIFOObY7MUEuXoNIpmm+k3PLSIvAAq/fdXPbCzfRKXXyAPkH7LZT9yz/PJ8q4Zu GF690bsKOPHwf+QETRqU8t7/2wFzeLrQEHKVWn7U+NI/zbphq93hRzmMgTW3tT7ENi0M GfAI8Ihds/103SiuaqfWcKfWGBbXzp7kGp7Co/6w2A0nhRmzcnwyBoSxoSscWkOQQCC2 okU8CtEO0DNGEZSrp/f6afuoFE7L7AikFQxhhCGoTFqDMNMZ6G1+z2DnljzD66zNDiPo SkJykodkAZhUKslf5IlViEiv+sXkeVj767fNpVnBH1vvPYc4/f6Nm9T+xWeja2c72xOE unFQ== X-Gm-Message-State: AKaTC01/eh6nLo2j19bWba9c37ifHRPzHWLVE51rqOj5nm30BC6wRXk79QAaWDQnMPFuHwOCPmKRTUkrTcUovw== X-Received: by 10.200.39.230 with SMTP id x35mr34905967qtx.259.1480620557027; Thu, 01 Dec 2016 11:29:17 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <87r35rxxo1.fsf@linux-m68k.org> References: <20161201185641.GA15507@intel.com> <87r35rxxo1.fsf@linux-m68k.org> From: "H.J. Lu" Date: Thu, 1 Dec 2016 11:29:16 -0800 Message-ID: Subject: Re: [PATCH] [BZ #20900] Call __res_vinit if _PATH_RESCONF is changed To: Andreas Schwab Cc: "H.J. Lu" , GNU C Library On Thu, Dec 1, 2016 at 11:21 AM, Andreas Schwab wrote: > On Dez 01 2016, "H.J. Lu" wrote: > >> @@ -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); > > This isn't thread-safe. > True. We can use __thread: diff --git a/resolv/res_libc.c b/resolv/res_libc.c index 47b2d42..f5b40ae 100644 --- a/resolv/res_libc.c +++ b/resolv/res_libc.c @@ -104,7 +104,7 @@ __res_maybe_init (res_state resp, int preinit) /* Call __res_vinit if _PATH_RESCONF has been changed since the last time. */ if (stat (_PATH_RESCONF, &buf) == 0) { - static struct timespec mtime; + static __thread struct timespec mtime; if (mtime.tv_sec != buf.st_mtim.tv_sec || mtime.tv_nsec != buf.st_mtim.tv_nsec) { mtime = buf.st_mtim;