summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2012-06-12 22:48:17 +0200
committerJouke Witteveen <j.witteveen@gmail.com>2012-06-12 22:48:17 +0200
commit4255f154975cc07d3d2a1e5af9a6dd37efac486d (patch)
treef6848f5ef1bdc13ac383ca8fa14a17a5116135b5
parent2e15ac5e029f1ef43dc38b33eb0f2dc9b8f5a4ba (diff)
downloadnetctl-4255f154975cc07d3d2a1e5af9a6dd37efac486d.tar.gz
netctl-4255f154975cc07d3d2a1e5af9a6dd37efac486d.tar.xz
Don't wait unnecessarily on bring_interface up
Good drivers indicate when they're up by the IFF_UP flag. This is the end of the (undocumented) UP_SLEEP variable and introduction of the UP_TIMEOUT (in seconds, default: 5) variable. This has 'noticeable speed improvement'-potential.
-rwxr-xr-xscripts/wifi-menu2
-rw-r--r--src/network16
2 files changed, 13 insertions, 5 deletions
diff --git a/scripts/wifi-menu b/scripts/wifi-menu
index 1140b85..1f0e423 100755
--- a/scripts/wifi-menu
+++ b/scripts/wifi-menu
@@ -206,7 +206,7 @@ fi
cd / # We do not want to spawn anything that can block unmounting
is_interface "$INTERFACE" || exit_fail "No such interface: $INTERFACE"
-if [[ -z "$(ip link show dev "$INTERFACE" up 2> /dev/null)" ]]; then
+if ! interface_is_up "$INTERFACE"; then
[[ -f "$IFACE_DIR/$INTERFACE" ]] && . "$IFACE_DIR/$INTERFACE"
bring_interface up "$INTERFACE" || exit_fail "Interface unavailable"
SPAWNED_INTERFACE=1
diff --git a/src/network b/src/network
index ebf9ee6..4858144 100644
--- a/src/network
+++ b/src/network
@@ -345,8 +345,7 @@ set_profile() {
# optionally link it to a profile.
#
set_iface() {
- local PROFILE="$3"
- [[ -z "$PROFILE" ]] && PROFILE=external
+ local PROFILE="${3:-external}"
if [[ "$1" == "up" ]]; then
echo "PROFILE='$PROFILE'" > "$STATE_DIR/interfaces/$2"
elif [[ "$1" == "down" ]]; then
@@ -364,19 +363,28 @@ is_interface() {
return 0
}
+interface_is_up() {
+ local flags="$(< "/sys/class/net/$1/flags")"
+ # IFF_UP is defined as 0x1 in linux/if.h
+ (( flags & 0x1 ))
+}
+
## Changes a network interface state.
# $1: up, flush, or down.
# $2: the interface name
bring_interface()
{
- local INTERFACE="$2"
+ local INTERFACE="$2" timeout="${UP_TIMEOUT:-5}"
case "$1" in
up)
if ! ( eval $IFACE_UP ); then
return 1
fi
ip link set dev "$INTERFACE" up &>/dev/null
- sleep "${UP_SLEEP:-2}"
+ while ! interface_is_up "$INTERFACE"; do
+ (( timeout-- > 0 )) || return 1
+ sleep 1
+ done
;;
flush|down)
if ! ( eval $IFACE_DOWN ); then