about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThorsten Kukuk <kukuk@suse.de>2013-08-16 14:54:23 -0400
committerMike Frysinger <vapier@gentoo.org>2014-02-08 09:21:03 -0500
commit6a714e48586aa7f21d2eeef9195cee57c9ebaa60 (patch)
tree04e26b709dbb1dd9d9aae45de457036a22519018
parentce3e26b03abb5d1f20117fa3e80b31bfee53ee33 (diff)
downloadglibc-6a714e48586aa7f21d2eeef9195cee57c9ebaa60.tar.gz
glibc-6a714e48586aa7f21d2eeef9195cee57c9ebaa60.tar.xz
glibc-6a714e48586aa7f21d2eeef9195cee57c9ebaa60.zip
reload /etc/resolv.conf when it has changed
if /etc/resolv.conf is updated, then make sure applications
already running get the updated information.

ripped from SuSE

http://bugs.gentoo.org/177416
-rw-r--r--resolv/res_libc.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/resolv/res_libc.c b/resolv/res_libc.c
index ee3fa2114b..f30b3a9104 100644
--- a/resolv/res_libc.c
+++ b/resolv/res_libc.c
@@ -22,6 +22,7 @@
 #include <arpa/nameser.h>
 #include <resolv.h>
 #include <bits/libc-lock.h>
+#include <sys/stat.h>
 
 
 /* The following bit is copied from res_data.c (where it is #ifdef'ed
@@ -95,6 +96,20 @@ int
 __res_maybe_init (res_state resp, int preinit)
 {
 	if (resp->options & RES_INIT) {
+		static time_t last_mtime, last_check;
+		time_t now;
+		struct stat statbuf;
+
+		time (&now);
+		if (now != last_check) {
+			last_check = now;
+			if (stat (_PATH_RESCONF, &statbuf) == 0 && last_mtime != statbuf.st_mtime) {
+				last_mtime = statbuf.st_mtime;
+				atomicinclock (lock);
+				atomicinc (__res_initstamp);
+				atomicincunlock (lock);
+			}
+		}
 		if (__res_initstamp != resp->_u._ext.initstamp) {
 			if (resp->nscount > 0)
 				__res_iclose (resp, true);