From 174ff7d754b272cbf6169bfbb245dbd12b392830 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Tue, 10 Dec 2019 17:24:20 +0300 Subject: [PATCH] base-files: send informational UDP message each second waiting The preinit network initialisation and failsafe informational message are inherently racy as the interface takes some time to become functional after "ip link set $pi_ifname up" command. Consider this timing: [ 12.002713] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready [ 12.008819] IPv6: ADDRCONF(NETDEV_UP): eth1.1: link is not ready [ 12.118877] random: procd: uninitialized urandom read (4 bytes read) [ 13.068614] eth1: link up (1000Mbps/Full duplex) [ 13.073309] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready [ 13.080445] IPv6: ADDRCONF(NETDEV_CHANGE): eth1.1: link becomes ready Since the UDP message was sent prior to link becoming ready, it was never seen on the wire. The default failsafe timeout is set to 2 seconds, so with this patch there are two attempts to send the message, one spent in vain, and the other visible in tcpdump on an attached host. Of course, in cases when the interface is brought up faster it leads to two messages, however it should be harmless. This patch (almost) doesn't affect normal boot time while still allowing to enter failsafe reliably with a single button press, matching the official "generic failsafe" documentation. Signed-off-by: Paul Fertser --- package/base-files/files/lib/preinit/30_failsafe_wait | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package/base-files/files/lib/preinit/30_failsafe_wait b/package/base-files/files/lib/preinit/30_failsafe_wait index dd9c7e2b59..85dca398fa 100644 --- a/package/base-files/files/lib/preinit/30_failsafe_wait +++ b/package/base-files/files/lib/preinit/30_failsafe_wait @@ -31,6 +31,8 @@ fs_wait_for_key () { lock $keypress_wait { while [ $timer -gt 0 ]; do + pi_failsafe_net_message=true \ + preinit_net_echo "Please press button now to enter failsafe" echo "$timer" >$keypress_sec timer=$(($timer - 1)) sleep 1 @@ -88,9 +90,6 @@ failsafe_wait() { } grep -q 'failsafe=' /proc/cmdline && FAILSAFE=true && export FAILSAFE if [ "$FAILSAFE" != "true" ]; then - pi_failsafe_net_message=true - preinit_net_echo "Please press button now to enter failsafe" - pi_failsafe_net_message=false fs_wait_for_key f 'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE=true [ -f "/tmp/failsafe_button" ] && FAILSAFE=true && echo "- failsafe button "`cat /tmp/failsafe_button`" was pressed -" [ "$FAILSAFE" = "true" ] && export FAILSAFE && touch /tmp/failsafe -- 2.25.1