]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
reload /etc/resolv.conf when it has changed
authorThorsten Kukuk <kukuk@suse.de>
Fri, 16 Aug 2013 18:54:23 +0000 (14:54 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 8 Feb 2014 14:21:03 +0000 (09:21 -0500)
if /etc/resolv.conf is updated, then make sure applications
already running get the updated information.

ripped from SuSE

http://bugs.gentoo.org/177416

resolv/res_libc.c

index ee3fa2114b7051b86f6f9676f1151d1435dedb9d..f30b3a9104c180e23717e978a5ce21df60822742 100644 (file)
@@ -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);