skeleton: optionally wait for network interfaces to appear
authorJérôme Pouiller <jezz@sysmic.org>
Thu, 29 Oct 2015 09:00:18 +0000 (10:00 +0100)
committerThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Mon, 2 Nov 2015 15:51:47 +0000 (16:51 +0100)
This patch has same purpose than 49964858f45d2243c513e6d362e992ad89ec7a45:

  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.

However, wait-delay hook is enabled only if wait-delay property appears
in /etc/network/interfaces. This patch enable it automaticaly when
interface is configured through DHCP at bootup. But, if user choose
to write /etc/network/interface himself, he have to explicitly
set wait-delay.

Signed-off-by: Jérôme Pouiller <jezz@sysmic.org>
Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
package/skeleton/skeleton.mk
system/skeleton/etc/network/if-pre-up.d/wait_iface [new file with mode: 0755]

index 920d3b42d3eaaeb905883bd5e3bedce391a0569a..d1b797ddcf26fd4b65a9d57eb9734ce1c4b0ee0b 100644 (file)
@@ -89,6 +89,7 @@ define SET_NETWORK_DHCP
                echo ;                                               \
                echo "auto $(NETWORK_DHCP_IFACE)";                   \
                echo "iface $(NETWORK_DHCP_IFACE) inet dhcp";        \
+               echo "  wait-delay 15";                              \
        ) >> $(TARGET_DIR)/etc/network/interfaces
 endef
 endif
diff --git a/system/skeleton/etc/network/if-pre-up.d/wait_iface b/system/skeleton/etc/network/if-pre-up.d/wait_iface
new file mode 100755 (executable)
index 0000000..ebccff2
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# 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. IF_WAIT_DELAY is in seconds.
+
+if [ "${IF_WAIT_DELAY}" -a ! -e "/sys/class/net/${IFACE}" ]; then
+    printf "Waiting for interface %s to appear" "${IFACE}"
+    while [ ${IF_WAIT_DELAY} -gt 0 ]; do
+        if [ -e "/sys/class/net/${IFACE}" ]; then
+            printf "\n"
+            exit 0
+        fi
+        sleep 1
+        printf "."
+        : $((IF_WAIT_DELAY -= 1))
+    done
+    printf " timeout!\n"
+    exit 1
+fi
+