From: Arnout Vandecappelle <arnout@mind.be>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH] package/skeleton: add a startup script to wait for slow network interfaces
Date: Sat, 3 Oct 2015 14:51:03 +0100 [thread overview]
Message-ID: <560FDD47.6090707@mind.be> (raw)
In-Reply-To: <1443879105-3036-1-git-send-email-yann.morin.1998@free.fr>
On 03-10-15 14:31, Yann E. MORIN wrote:
> 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.
>
> If Buildroot is configured to do a DHCP on an interface, install a
> startup script, just before S40network, that waits for that interface.
>
> Since Buildroot can only be configured to run DHCP on a single interface,
> we do not need a script that waits for more than one interface.
>
> Closes #8116.
>
> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> ---
> package/skeleton/S39wait-for-network-if | 43 +++++++++++++++++++++++++++++++++
Argh, you're adding an init script to skeleton! That's evil(TM)! :-)
Seriously, this should be part of package/initscripts/init.d/S40network instead.
> package/skeleton/skeleton.mk | 2 ++
> 2 files changed, 45 insertions(+)
> create mode 100644 package/skeleton/S39wait-for-network-if
>
> diff --git a/package/skeleton/S39wait-for-network-if b/package/skeleton/S39wait-for-network-if
> new file mode 100644
> index 0000000..010026e
> --- /dev/null
> +++ b/package/skeleton/S39wait-for-network-if
> @@ -0,0 +1,43 @@
> +#!/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. WAIT_DELAY is in seconds.
> +WAIT_DELAY=15
> +
> +wait_for_IF() {
> + IF="$(sed -r -e '/^auto lo/d;' \
I believe the ; are redundant when you use -e (at least that's what we do in
other cases).
> + -e '/^auto (.+)$/!d;' \
> + -e 's//\1/;' \
This one got me looking at the sed man page and I'm still surprised that it
works. Basically, this s command is reusing the same address as given on the
previous line, but without the ! modifier, right?
Regards,
Arnout
> + /etc/network/interfaces
> + )"
> + if [ -z "${IF}" -o -e "/sys/class/net/${IF}" ]; then
> + return 0
> + fi
> + printf "Waiting for interface %s to appear" "${IF}"
> + wait=${WAIT_DELAY}
> + while [ ${wait} -gt 0 ]; do
> + if [ -e "/sys/class/net/${IF}" ]; then
> + printf " yes\n"
> + return 0
> + fi
> + sleep 1
> + printf "."
> + : $((wait--))
> + done
> + printf " no.\n"
> + return 1
> +}
> +
> +case "$1" in
> + start)
> + wait_for_IF
> + ;;
> + stop)
> + ;;
> + restart)
> + "$0" start
> + ;;
> + *)
> + echo "Usage: $0 {start|stop|restart}"
> +esac
> diff --git a/package/skeleton/skeleton.mk b/package/skeleton/skeleton.mk
> index 48e7085..733b86f 100644
> --- a/package/skeleton/skeleton.mk
> +++ b/package/skeleton/skeleton.mk
> @@ -76,6 +76,8 @@ define SET_NETWORK_DHCP
> echo "auto $(NETWORK_DHCP_IFACE)"; \
> echo "iface $(NETWORK_DHCP_IFACE) inet dhcp"; \
> ) >> $(TARGET_DIR)/etc/network/interfaces
> + $(INSTALL) -D -m 0755 package/skeleton/S39wait-for-network-if \
> + $(TARGET_DIR)/etc/init.d/S39wait-for-network-if
> endef
> endif
>
>
--
Arnout Vandecappelle arnout at mind be
Senior Embedded Software Architect +32-16-286500
Essensium/Mind http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
next prev parent reply other threads:[~2015-10-03 13:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-03 13:31 [Buildroot] [PATCH] package/skeleton: add a startup script to wait for slow network interfaces Yann E. MORIN
2015-10-03 13:51 ` Arnout Vandecappelle [this message]
2015-10-03 13:59 ` Peter Korsgaard
2015-10-03 14:01 ` Peter Korsgaard
2015-10-16 9:42 ` Peter Korsgaard
2015-10-03 15:47 ` Thomas Petazzoni
2015-10-03 18:29 ` Maxime Hadjinlian
2015-10-03 18:43 ` Arnout Vandecappelle
2015-10-03 18:46 ` Maxime Hadjinlian
2015-10-04 8:23 ` Peter Korsgaard
2015-10-19 8:47 ` Jérôme Pouiller
2015-10-19 10:15 ` Peter Korsgaard
2015-10-19 10:22 ` Jérôme Pouiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=560FDD47.6090707@mind.be \
--to=arnout@mind.be \
--cc=buildroot@busybox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.