Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame^] | 1 | From fe2ae4f877928dd6bff5bac3f15bce4b50d2bd12 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Wed, 18 Mar 2015 00:51:16 +0000 |
| 4 | Subject: [PATCH 21/27] eglibc: cherry-picked from |
| 5 | http://www.eglibc.org/archives/patches/msg00772.html |
| 6 | |
| 7 | It hasn't yet been merged into glibc |
| 8 | |
| 9 | Upstream-Status: Pending |
| 10 | |
| 11 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 12 | --- |
| 13 | resolv/res_libc.c | 15 +++++++++++++-- |
| 14 | 1 file changed, 13 insertions(+), 2 deletions(-) |
| 15 | |
| 16 | diff --git a/resolv/res_libc.c b/resolv/res_libc.c |
| 17 | index ee3fa21..29e2340 100644 |
| 18 | --- a/resolv/res_libc.c |
| 19 | +++ b/resolv/res_libc.c |
| 20 | @@ -22,12 +22,13 @@ |
| 21 | #include <arpa/nameser.h> |
| 22 | #include <resolv.h> |
| 23 | #include <bits/libc-lock.h> |
| 24 | - |
| 25 | +#include <sys/stat.h> |
| 26 | |
| 27 | /* The following bit is copied from res_data.c (where it is #ifdef'ed |
| 28 | out) since res_init() should go into libc.so but the rest of that |
| 29 | file should not. */ |
| 30 | |
| 31 | +__libc_lock_define_initialized (static, lock); |
| 32 | extern unsigned long long int __res_initstamp attribute_hidden; |
| 33 | /* We have atomic increment operations on 64-bit platforms. */ |
| 34 | #if __WORDSIZE == 64 |
| 35 | @@ -35,7 +36,6 @@ extern unsigned long long int __res_initstamp attribute_hidden; |
| 36 | # define atomicincunlock(lock) (void) 0 |
| 37 | # define atomicinc(var) catomic_increment (&(var)) |
| 38 | #else |
| 39 | -__libc_lock_define_initialized (static, lock); |
| 40 | # define atomicinclock(lock) __libc_lock_lock (lock) |
| 41 | # define atomicincunlock(lock) __libc_lock_unlock (lock) |
| 42 | # define atomicinc(var) ++var |
| 43 | @@ -94,7 +94,18 @@ res_init(void) { |
| 44 | int |
| 45 | __res_maybe_init (res_state resp, int preinit) |
| 46 | { |
| 47 | + static time_t last_mtime; |
| 48 | + struct stat statbuf; |
| 49 | + int ret; |
| 50 | + |
| 51 | if (resp->options & RES_INIT) { |
| 52 | + ret = stat (_PATH_RESCONF, &statbuf); |
| 53 | + __libc_lock_lock (lock); |
| 54 | + if ((ret == 0) && (last_mtime != statbuf.st_mtime)) { |
| 55 | + last_mtime = statbuf.st_mtime; |
| 56 | + atomicinc (__res_initstamp); |
| 57 | + } |
| 58 | + __libc_lock_unlock (lock); |
| 59 | if (__res_initstamp != resp->_u._ext.initstamp) { |
| 60 | if (resp->nscount > 0) |
| 61 | __res_iclose (resp, true); |
| 62 | -- |
| 63 | 2.1.4 |
| 64 | |