[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#272265: libc6: Programs should reload /etc/resolv.conf when it changes

Package:  libc6
Version:  2.3.2.ds1-16
Tags:     patch
Severity: wishlist

The current DNS resolver in glibc only read the content of
/etc/resolv.conf when a program starts (or during the first call to
one of the resolver function).  This is a problem for long-lasting
programs on for example laptops, where the content of the file may
change when a new IP configuration is fetched using DHCP.  A
workaround is to use nscd and call 'nscd -i hosts' when the file
changes, but it would be better if the content of the file was reread
automatically when it changes.

The following patch by Torstein Kukuk from
fixes this problem, by making sure the timestamp of the file is
checked every time a DNS lookup is done.

Please include this patch in the default glibc used in Debian.  It
would make it so much useful on machines with changing IP

--- resolv/res_libc.c	6 Aug 2004 17:52:53 -0000	1.20
+++ resolv/res_libc.c	9 Aug 2004 15:14:47 -0000
@@ -22,7 +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
    out) since res_init() should go into libc.so but the rest of that
@@ -100,8 +100,17 @@ res_init(void) {
 __res_maybe_init (res_state resp, int preinit)
-	if (resp->options & RES_INIT) {
-		if (__res_initstamp != resp->_u._ext.initstamp) {
+  static time_t last_mtime;
+  struct stat statbuf;
+  int ret;
+  if (resp->options & RES_INIT) {
+	ret = stat (_PATH_RESCONF, &statbuf);
+		if (__res_initstamp != resp->_u._ext.initstamp
+		  || (ret == 0) && (last_mtime != statbuf.st_mtime))
+		  {
+		        last_mtime = statbuf.st_mtime;
 			if (resp->nscount > 0) {
 				__res_nclose (resp);
 				for (int ns = 0; ns < MAXNS; ns++) {

Reply to: