This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gethby* and dynamic DNS assignment



I got the following bug report:
> When using wwwoffle with a dialup connection and dynamic DNS assignent,
> one has to restart the wwwoffle daemon, because it is no longer able to resolve
> names, when resolv.conf has been changed (See the FAQ). Wouldn't it be possible
> to fix glibc in that respect?
> http://www.gedanken.demon.co.uk/wwwoffle/version-2.6/FAQ.html#Q-3.2

I decided to handle this problem with the following patch.  What do
you think?  This leads unfortunatly to a stat with every gethostby*
call. Has anybody a better idea?

Is this ok to commit for glibc 2.2.1?

Andreas

2001-01-09  Andreas Jaeger  <aj@suse.de>

	* resolv/gethnamaddr.c (check_init_res): New function.
	(gethostbyname): Use it.
	(gethostbyname2): Use it.
	(gethostbyaddr): Use it.

============================================================
Index: resolv/gethnamaddr.c
--- resolv/gethnamaddr.c	2000/04/30 04:15:40	1.34
+++ resolv/gethnamaddr.c	2001/01/09 15:10:00
@@ -67,6 +67,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <syslog.h>
+#include <sys/stat.h>
 
 #ifndef LOG_AUTH
 # define LOG_AUTH 0
@@ -485,13 +486,36 @@
 	return (NULL);
 }
 
+/* Check if _res has been initialized and if /etc/resolv.conf has been
+   modified since the initialization.  Re-initialize if needed.
+*/
+static int
+check_init_res (void)
+{
+  static time_t last_mtime;
+  struct stat statbuf;
+  int ret;
+
+  ret = stat (_PATH_RESCONF, &statbuf);
+
+  if (((_res.options & RES_INIT) == 0)
+      || ((ret == 0) && (last_mtime != statbuf.st_mtime)))
+    {
+      last_mtime = statbuf.st_mtime;
+      if (__res_ninit (&_res) == -1)
+	return 1;
+    }
+  return 0;
+}
+
+
 struct hostent *
 gethostbyname(name)
 	const char *name;
 {
 	struct hostent *hp;
 
-	if ((_res.options & RES_INIT) == 0 && __res_ninit(&_res) == -1) {
+	if (!check_init_res ()) {
 		__set_h_errno (NETDB_INTERNAL);
 		return (NULL);
        }
@@ -514,7 +538,7 @@
 	int n, size, type, len;
 	extern struct hostent *_gethtbyname2();
 
-	if ((_res.options & RES_INIT) == 0 && __res_ninit(&_res) == -1) {
+	if (!check_init_res ()) {
 		__set_h_errno (NETDB_INTERNAL);
 		return (NULL);
 	}
@@ -643,7 +667,7 @@
 #endif /*SUNSECURITY*/
 	extern struct hostent *_gethtbyaddr();
 
-	if ((_res.options & RES_INIT) == 0 && __res_ninit(&_res) == -1) {
+	if (!check_init_res ()) {
 		__set_h_errno (NETDB_INTERNAL);
 		return (NULL);
 	}
-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]