In init.d/net-online "ping -c 1 $ping_test_host" command waits for 3 seconds when host is unreachable but only 1 second is subtracted from the timeout variable ": $((timeout -= 1))". It seems to wait for 3 seconds based on value of "mcast_solicit" (/proc/sys/net/ipv4/neigh/$IFNAME/mcast_solicit) which defaults to 3. Instead of assuming it to always be the default we can simply calculate how long the command took: ping_start="$(date +%s)" ping -c 1 $ping_test_host > /dev/null 2>&1 rc=$? ping_end="$(date +%s)" [ $rc -eq 0 ] && break : $((timeout -= (ping_end - ping_start)))
(In reply to nnnn20430 from comment #0) > In init.d/net-online "ping -c 1 $ping_test_host" command waits for 3 seconds By default, ping makes a reverse DNS request for every ping reply, so my guess is that it is DNS reply that ping waits for 3 seconds. So to fix this problem it is required to add -n for ping command. Yet we have another bug here. If ping receives reply very fast script waits much less that timeout value. In my case it fails with error less then second, while I put 120 seconds of timeout: ======================================================= ~ # time /etc/init.d/net-online start * Caching service dependencies ... [ ok ] * Checking to see if the network is online ... * The network is offline [ !! ] * ERROR: net-online failed to start real 0m0.938s user 0m0.669s sys 0m0.185s ======================================================= To fix we need to add sleep 1 before we subtract second with the following line: : $((timeout -= 1))
Patch to fix both issues: --- net-online 2021-07-03 11:47:59.916318058 +0300 +++ net-online 2021-07-03 11:47:52.406308782 +0300 @@ -65,9 +65,10 @@ ping_test_host="${ping_test_host:-google.com}" if [ -n "$ping_test_host" ]; then while $infinite || [ $timeout -gt 0 ]; do - ping -c 1 $ping_test_host > /dev/null 2>&1 + ping -n -c 1 $ping_test_host > /dev/null 2>&1 rc=$? [ $rc -eq 0 ] && break + sleep 1 : $((timeout -= 1)) done fi
See https://github.com/OpenRC/openrc/commit/e21b01b97e84f81589f52e087d2b2ac53f0bf144 but maybe we want -n too.