[BZ,#20900] Call __res_vinit if _PATH_RESCONF is changed

Message ID CAMe9rOqOUUHvZ859xZKbQdsXqy-4z-MdydU2gk2bO=-gzfbhwg@mail.gmail.com
State New, archived
Headers

Commit Message

H.J. Lu Dec. 1, 2016, 7:29 p.m. UTC
  On Thu, Dec 1, 2016 at 11:21 AM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> On Dez 01 2016, "H.J. Lu" <hongjiu.lu@intel.com> 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:
  

Patch

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;