Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [git commit] package/initscripts: S40network: wait for network interfaces to appear
@ 2015-10-16  7:16 Peter Korsgaard
  2015-10-26 20:07 ` Ryan Barnett
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Korsgaard @ 2015-10-16  7:16 UTC (permalink / raw)
  To: buildroot

commit: http://git.buildroot.net/buildroot/commit/?id=49964858f45d2243c513e6d362e992ad89ec7a45
branch: http://git.buildroot.net/buildroot/commit/?id=refs/heads/master

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 |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/package/initscripts/init.d/S40network b/package/initscripts/init.d/S40network
index 7b11d8b..a8d7c5d 100755
--- a/package/initscripts/init.d/S40network
+++ b/package/initscripts/init.d/S40network
@@ -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
 	;;

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-10-27 22:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-16  7:16 [Buildroot] [git commit] package/initscripts: S40network: wait for network interfaces to appear Peter Korsgaard
2015-10-26 20:07 ` Ryan Barnett
2015-10-26 20:23   ` Peter Korsgaard
     [not found]     ` <CADZ9A7pN8Tq8NzDbnNDjjSP0Y7Edvo7TbngcFNhttO+v+ybMXg@mail.gmail.com>
2015-10-26 20:56       ` Peter Korsgaard
2015-10-26 21:04       ` Yann E. MORIN
2015-10-26 21:24         ` Ryan Barnett
2015-10-27  9:22   ` Nicolas Cavallari
2015-10-27 22:39     ` Arnout Vandecappelle
2015-10-27 22:46       ` Peter Korsgaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox