[PATCH] [BZ #20900] Call __res_vinit if _PATH_RESCONF is changed
H.J. Lu
hongjiu.lu@intel.com
Thu Dec 1 18:56:00 GMT 2016
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 <sys/stat.h>.
(__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 <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
+#include <sys/stat.h>
#include <resolv.h>
#include <libc-lock.h>
@@ -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) {
--
2.7.4
More information about the Libc-alpha
mailing list