Tcl Source Code

Artifact [db5e672965]
Login

Artifact db5e672965d800d05586521ffaf5f59ff9688409:

Attachment "tclUnixCompat.diff" to ticket [1777366fff] added by dkf 2007-08-20 15:07:12.
--- unix/tclUnixCompat.c.orig	2006-09-13 02:05:03.000000000 +0400
+++ unix/tclUnixCompat.c	2007-08-19 02:00:15.000000000 +0400
@@ -17,6 +17,12 @@
 #include <errno.h>
 #include <string.h>
 
+#include <resolv.h>
+struct {
+  time_t mTime;
+  time_t stampTime;
+} resolvConfTimes;
+
 /*
  * Used to pad structures at size'd boundaries
  *
@@ -40,6 +46,8 @@
 
 #ifdef TCL_THREADS
 
+static Tcl_Mutex mtLock;
+
 typedef struct ThreadSpecificData {
 
     struct passwd pwd;
@@ -573,6 +581,28 @@
 struct hostent *
 TclpGetHostByName(const char *name)
 {
+    time_t t;
+    struct stat st;
+
+    time(&t);
+#if defined(TCL_THREADS) 
+    Tcl_MutexLock(&mtLock);
+#endif
+    /*
+     resolvConfTimes.stampTime == resolvConfTimes.mTime == 0 is ok
+     */
+    if ( resolvConfTimes.stampTime + 5 < t ) {
+      resolvConfTimes.stampTime = t;
+      if ( !stat("/etc/resolv.conf", &st) && 
+          ( st.st_mtime > resolvConfTimes.mTime ) ) {
+        res_init();
+        resolvConfTimes.mTime = st.st_mtime;
+      }
+    }
+#if defined(TCL_THREADS)
+    Tcl_MutexUnlock(&mtLock);
+#endif
+
 #if !defined(TCL_THREADS) || defined(HAVE_MTSAFE_GETHOSTBYNAME)
     return gethostbyname(name);
 #else