From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0DCB0138334 for ; Thu, 12 Jul 2018 06:52:12 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1FC04E08D9; Thu, 12 Jul 2018 06:52:11 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id CBE36E08D9 for ; Thu, 12 Jul 2018 06:52:09 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D2D09335CA8 for ; Thu, 12 Jul 2018 06:52:06 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C71CF364 for ; Thu, 12 Jul 2018 06:52:04 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1531378263.6f261f1beec1ecbfe7ec39ae33b5a7f947292f6e.robbat2@OpenRC> Subject: [gentoo-commits] proj/netifrc:master commit in: init.d/, doc/ X-VCS-Repository: proj/netifrc X-VCS-Files: doc/net.example.BSD.in doc/net.example.Linux.in init.d/net.lo.in X-VCS-Directories: init.d/ doc/ X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: 6f261f1beec1ecbfe7ec39ae33b5a7f947292f6e X-VCS-Branch: master Date: Thu, 12 Jul 2018 06:52:04 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: c488c6d8-a862-449e-a262-17fc40eead52 X-Archives-Hash: 9faa724ab0b1692c697dde7947fe94bf commit: 6f261f1beec1ecbfe7ec39ae33b5a7f947292f6e Author: Maciej S. Szmigiero maciej szmigiero name> AuthorDate: Wed Nov 29 19:49:27 2017 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Thu Jul 12 06:51:03 2018 +0000 URL: https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=6f261f1b init.d/net.lo: add a configurable presence timeout Sometimes one may want to wait for a particular interface to show up when starting its service. For example if a "net.foo" service is in the "default" runlevel so it provides (or co-provides) the "net" service and it takes a while for the "foo" interface to initialize and show up in the system during boot this interface initialization will race with starting of this "net.foo" service by the service manager - if the interface hasn't shown up yet the service won't be able to start (and so will services that depend on it). This setting specifies how long we'll wait for an interface to show up in this case (in seconds). For backward-compatibility the default is 0 (don't wait at all) - this matches the existing behavior of netifrc, so existing deployments aren't affected by this change. This new setting is similar to an already present "wait for carrier timeout" setting. Signed-off-by: Maciej S. Szmigiero maciej.szmigiero.name> (cherry picked from commit 64f33a2032b4972a25cad6405678f678a5a269ff) Closes: https://github.com/gentoo/netifrc/pull/28 doc/net.example.BSD.in | 16 ++++++++++++++++ doc/net.example.Linux.in | 16 ++++++++++++++++ init.d/net.lo.in | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/doc/net.example.BSD.in b/doc/net.example.BSD.in index 1df32e0..4c574b4 100644 --- a/doc/net.example.BSD.in +++ b/doc/net.example.BSD.in @@ -77,6 +77,22 @@ # Some users may need to alter the MTU - here's how #mtu_eth0="1500" +# Sometimes you may want to wait for a particular interface to show up +# when starting its service. +# For example if a net.foo service is in the "default" runlevel so it +# provides (or co-provides) the "net" service and it takes a while for the +# "foo" interface to initialize and show up in the system during a boot this +# will race with starting of net.foo service by the service manager - if the +# interface hasn't shown up yet the service won't be able start (and so +# will services that depend on it). +# This setting specifies how long we wait for an interface to show up +# in this case (in seconds). +# The current default is 0 - we need an interface to be already present +# in the system when its service is started. +#presence_timeout=0 +# This setting can be also adjusted on a per-interface basis: +#presence_timeout_eth0=10 + # Most drivers that report carrier status function correctly, but some do not # One of these faulty drivers is for the Intel e1000 network card, but only # at boot time. To get around this you may alter the carrier_timeout value for diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in index c0cfd38..3b414ba 100644 --- a/doc/net.example.Linux.in +++ b/doc/net.example.Linux.in @@ -126,6 +126,22 @@ # tables you may have to set a global metric as the due to a simple read of # the routing table taking over a minute at a time. +# Sometimes you may want to wait for a particular interface to show up +# when starting its service. +# For example if a net.foo service is in the "default" runlevel so it +# provides (or co-provides) the "net" service and it takes a while for the +# "foo" interface to initialize and show up in the system during a boot this +# will race with starting of net.foo service by the service manager - if the +# interface hasn't shown up yet the service won't be able start (and so +# will services that depend on it). +# This setting specifies how long we wait for an interface to show up +# in this case (in seconds). +# The current default is 0 - we need an interface to be already present +# in the system when its service is started. +#presence_timeout=0 +# This setting can be also adjusted on a per-interface basis: +#presence_timeout_eth0=10 + # Most drivers that report carrier status function correctly, but some do not # One of these faulty drivers is for the Intel e1000 network card, but only # at boot time. To get around this you may alter the carrier_timeout value for diff --git a/init.d/net.lo.in b/init.d/net.lo.in index b78a342..472ed0c 100644 --- a/init.d/net.lo.in +++ b/init.d/net.lo.in @@ -118,6 +118,37 @@ _flatten_array() _array_helper $1 } +_wait_for_presence() +{ + local timeout= + local rc= + + _exists && return 0 + + eval timeout=\$presence_timeout_${IFVAR} + timeout=${timeout:-${presence_timeout:-0}} + + [ ${timeout} -le 0 ] && return 1 + + einfon "Waiting for ${IFACE} to show up (${timeout} seconds)" + while [ ${timeout} -gt 0 ]; do + _exists + rc=$? + [ $rc -eq 0 ] && break + + sleep 1 + printf "." + : $(( timeout -= 1 )) + done + + if [ ${timeout} -le 0 ]; then + _exists + rc=$? + fi + echo + eend $rc +} + _wait_for_carrier() { local timeout= @@ -618,7 +649,7 @@ start() fi done - if ! _exists; then + if ! _wait_for_presence; then eerror "ERROR: interface ${IFACE} does not exist" eerror "Ensure that you have loaded the correct kernel module for your hardware" return 1