Skip to content

Commit 36af051

Browse files
haraldhdanimo
authored andcommitted
fix(network): correct regression in iface_has_carrier
Commit e25c536 introduced a regression in iface_has_carrier due to unclear variable naming.
1 parent ba4bcf5 commit 36af051

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

modules.d/40network/net-lib.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -760,31 +760,32 @@ type hostname > /dev/null 2>&1 \
760760

761761
iface_has_carrier() {
762762
local cnt=0
763-
local interface="$1" flags=""
763+
local iface="$1" flags=""
764764
local timeout
765-
[ -n "$interface" ] || return 2
766-
interface="/sys/class/net/$interface"
767-
[ -d "$interface" ] || return 2
765+
local iface_sys_path
766+
[ -n "$iface" ] || return 2
767+
iface_sys_path="/sys/class/net/$iface"
768+
[ -d "$iface_sys_path" ] || return 2
768769
timeout=$(getargs rd.net.timeout.carrier=)
769770
timeout=${timeout:-10}
770771
timeout=$((timeout * 10))
771772

772773
linkup "$1"
773774

774-
li=$(ip link show up dev "$interface")
775+
li=$(ip link show up dev "$iface")
775776
strstr "$li" "NO-CARRIER" && _no_carrier_flag=1
776777

777778
while [ $cnt -lt $timeout ]; do
778779
if [ -n "$_no_carrier_flag" ]; then
779-
li=$(ip link show up dev "$interface")
780+
li=$(ip link show up dev "$iface")
780781
# NO-CARRIER flag was cleared
781782
strstr "$li" "NO-CARRIER" || return 0
782-
elif ! [ -e "$interface/carrier" ]; then
783+
elif ! [ -e "$iface_sys_path/carrier" ]; then
783784
# sysfs not available and "NO-CARRIER" not displayed
784785
return 0
785786
fi
786787
# double check the syscfs carrier flag
787-
[ -e "$interface/carrier" ] && [ "$(cat "$interface"/carrier)" = 1 ] && return 0
788+
[ -e "$iface_sys_path/carrier" ] && [ "$(cat "$iface_sys_path"/carrier)" = 1 ] && return 0
788789
sleep 0.1
789790
cnt=$((cnt + 1))
790791
done

0 commit comments

Comments
 (0)