tags 766838 + patch
thanks

Dear maintainers,

my testing indicates that there are two distinct problems. First, for whatever reason, /etc/network/if-up.d/ntpdate is called with $IFACE = --all in addition to legitimate interfaces. This causes a race condition: If the $IFACE = --all instance wins, the other instances are prevented from doing anything useful.

Secondly, /etc/network/if-up.d/ntpdate is called somewhat early, i.e. when the interface is already up but before an IP address has been obtained via DHCP.

The attached patch fixes both issues for me. It contains a whitelist of interfaces /etc/network/if-up.d/ntpdate should act upon (eth*, wlan*) to avoid the bogus $IFACE = --all case. In hindsight, perhaps this should be turned into a blacklist containing "--all" only.

The second part of the patch builds upon Hartmut Buhrmester's suggestion to insert a "sleep" call, but parses ifconfig output until an IP address has been assigned. This part handles the IPv4 case only since I don't have an IPv6 network to test with.

I hope you'll find the patch useful!

Cheers,

Rene
--- /etc/network/if-up.d/ntpdate	2008-07-09 17:23:38.000000000 +0200
+++ ntpdate	2017-01-15 14:48:46.783164283 +0100
@@ -16,6 +16,12 @@
 	exit 0
 fi
 
+case "$IFACE" in
+        eth*) : ;;
+        wlan*) : ;;
+        *) exit 0;;
+esac
+
 # Check whether ntpdate was removed but not purged; it's useless to wait for 
 # it in that case.
 if [ ! -x /usr/sbin/ntpdate-debian ] && [ -d /usr/sbin ]; then
@@ -30,6 +36,16 @@
 	wait_for_file /usr/sbin/ntpdate-debian
 fi
 
+# Wait for DHCP to assign an IP address.
+if [ "$ADDRFAM" = "inet" ]; then
+	while ! ifconfig $LOGICAL | grep -q 'inet addr'; do
+		sleep 2
+	done
+fi
+
+# Wait a little while longer so routes and resolv.conf are in place, too.
+sleep 2
+
 LOCKFILE=/var/lock/ntpdate
 
 # Avoid running more than one at a time

Reply via email to