package dnsmasq
tags 627789 patch
stop

Here ya go.

-- 
Thomas
--- dnsmasq_ORIG	2011-02-20 03:21:14.000000000 +0100
+++ dnsmasq	2011-05-24 21:21:32.798425489 +0200
@@ -55,16 +55,38 @@
 	NMSRVRS="$RSLT"
 fi
 
+echo_mtime() {
+        # Echo the mtime of the file named in $1
+        #
+        # "ls -god --time-style='+%s' dnsmasq" yields, for example:
+        #     -rwxr-xr-x 1 2029 1306262847 dnsmasq
+        # The fourth field is the number of seconds since 1970-01-01 00:00:00 UTC
+	if [ "$1" ] && [ -f "$1" ] ; then
+	        ls -god --time-style='+%s' "$1" | { read prms hrdlnks sz scnds flnm ; echo "$scnds" ; }	
+	else
+		echo ""
+	fi
+}
+
+MTIME_OF_OLD_RSLVRLIST_FILE="$(echo_mtime "$RSLVRLIST_FILE")"
+
 clean_up() { rm -f "$TMP_FILE" ; }
 trap clean_up EXIT
+
 : >| "$TMP_FILE"
 for N in $NMSRVRS ; do echo "nameserver $N" >> "$TMP_FILE" ; done
-mv -f "$TMP_FILE" "$RSLVRLIST_FILE"
 
-# dnsmasq uses the mtime of the file to detect changes. This has a resolution of one second, 
-# so it's possible that if two or more changes occur rapidly, the second change could 
-# be missed. We avoid this possibility by delaying here.
-sleep 1
+MTIME_OF_NEW_RSLVRLIST_FILE="$(echo_mtime "$TMP_FILE")"
 
- 
+if [ "$MTIME_OF_OLD_RSLVRLIST_FILE" = "$MTIME_OF_NEW_RSLVRLIST_FILE" ] ; then
+	# Dnsmasq uses the mtime of the file, with a resolution of one second,
+	# to detect changes. This means that if a resolvconf update occurs
+	# within one second of the previous one (which is quite possible)
+	# then dnsmasq will fail to notice the change.  To work around this
+	# problem we sleep here to ensure that the new mtime is different.
+	sleep 1
+	echo "" >> "$TMP_FILE"  # Update mtime
+fi
+
+mv -f "$TMP_FILE" "$RSLVRLIST_FILE"
 

Reply via email to