Package: tcl8.4
Version: 8.4.15-1
Severity: important
Tags: patch

The problem reveales for me constantly when I close laptop lid at home
and open it in the office. Tkabber needs to be restarted since tcl calls
like 'socket $host $port' where host is a hostname (not an ip) try to
resolv host using old resolv.conf. Basicly, res_init needs to be called.

The enclosed patch solves the problem for me. Note that to finish the
fix other resolv-related wrappers need to be fixed the same way. Also
-lresolv must be added to LIBS.

--
Alexander Kotelnikov
Saint-Petersburg, Russia

-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.17-sacha
Locale: LANG=ru_RU.UTF-8, LC_CTYPE=ru_RU.UTF-8 (charmap=UTF-8)

Versions of packages tcl8.4 depends on:
ii  libc6                  2.3.6.ds1-13etch2 GNU C Library: Shared libraries

tcl8.4 recommends no packages.

-- no debconf information
--- 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

Reply via email to