]> rtime.felk.cvut.cz Git - coffee/buildroot.git/commitdiff
package/initscripts: S40network: wait for network interfaces to appear
authorYann E. MORIN <yann.morin.1998@free.fr>
Sat, 3 Oct 2015 13:31:45 +0000 (14:31 +0100)
committerPeter Korsgaard <peter@korsgaard.com>
Fri, 16 Oct 2015 07:16:58 +0000 (09:16 +0200)
On some machines, the network interface is slow to appear. For example,
on the Raspberry Pi, the network interface eth0 is an ethernet-over-USB,
and our standard boot process is too fast, so our network startup script
is called before the USB bus is compeltely enumerated, thus it can't
configure eth0.

Closes #8116.

[Peter: move to S40network, handle multiple interfaces]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
package/initscripts/init.d/S40network

index 7b11d8b90208a6bfb602e70e43bf108c8b48b470..a8d7c5df7863c0967e16af99b1cbd0ad97006fe4 100755 (executable)
@@ -6,8 +6,37 @@
 # Debian ifupdown needs the /run/network lock directory
 mkdir -p /run/network
 
+# In case we have a slow-to-appear interface (e.g. eth-over-USB),
+# and we need to configure it, wait until it appears, but not too
+# long either. WAIT_DELAY is in seconds.
+WAIT_DELAY=15
+
+wait_for_interfaces() {
+       IFACES=$(awk '/^auto/ { print $2 }' /etc/network/interfaces)
+       [ -n "$IFACES" ] || return
+
+       printf "Waiting for network interfaces to appear"
+
+       for i in $(seq $WAIT_DELAY); do
+           for IFACE in $IFACES; do
+               if [ ! -e "/sys/class/net/$IFACE" ]; then
+                   printf "."
+                   sleep 1
+                   continue 2
+               fi
+           done
+
+           printf " ok\n"; return
+       done
+
+       printf " timeout\n"
+       exit 1
+}
+
 case "$1" in
   start)
+       wait_for_interfaces
+
        echo "Starting network..."
        /sbin/ifup -a
        ;;