olsrd: hotplug: optimize execution-speed and simplify using already existing GLOBAL vars instead of encapsulating vars from function to function, cleanups and comments in source
This commit is contained in:
parent
0e4201a983
commit
3a1fd11883
1 changed files with 22 additions and 14 deletions
|
@ -11,7 +11,7 @@ olsrd_list_configured_interfaces()
|
||||||
# is disabled
|
# is disabled
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "$interface"
|
echo "$interface" # e.g. 'lan'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -19,26 +19,32 @@ olsrd_list_configured_interfaces()
|
||||||
} done
|
} done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
olsrd_interface_already_in_config()
|
||||||
|
{
|
||||||
|
# e.g.: 'Interface "eth0.1" "eth0.2" "wlan0"'
|
||||||
|
if grep -s ^'Interface ' '/var/etc/olsrd.conf' | grep -q "\"$DEVICE\""; then
|
||||||
|
logger -t olsrd_hotplug -p daemon.debug "[OK] already_active: '$INTERFACE' => '$DEVICE'"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
logger -t olsrd_hotplug -p daemon.info "[OK] ifup: '$INTERFACE' => '$DEVICE'"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
olsrd_interface_needs_adding()
|
olsrd_interface_needs_adding()
|
||||||
{
|
{
|
||||||
local interface="$1" # e.g. wlanadhocRADIO1
|
local testif
|
||||||
local device="$2" # e.g. wlan1-1
|
|
||||||
local myif
|
# likely and cheap operation:
|
||||||
local config="/var/etc/olsrd.conf"
|
olsrd_interface_already_in_config && return 1
|
||||||
|
|
||||||
for myif in $(olsrd_list_configured_interfaces); do {
|
for myif in $(olsrd_list_configured_interfaces); do {
|
||||||
[ "$myif" = "$interface" ] && {
|
[ "$myif" = "$interface" ] && {
|
||||||
if grep -s ^'Interface ' "$config" | grep -q "\"$device\""; then
|
olsrd_interface_already_in_config || return 0
|
||||||
logger -t olsrd_hotplug -p daemon.debug "[OK] already_active: $INTERFACE => $DEVICE"
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
logger -t olsrd_hotplug -p daemon.info "[OK] ifup: $INTERFACE => $DEVICE"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
} done
|
} done
|
||||||
|
|
||||||
logger -t olsrd_hotplug -p daemon.debug "[OK] interface $INTERFACE not used for olsrd"
|
logger -t olsrd_hotplug -p daemon.debug "[OK] interface '$INTERFACE' => '$DEVICE' not used for olsrd"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +53,9 @@ case "$ACTION" in
|
||||||
# only work after the first normal startup
|
# only work after the first normal startup
|
||||||
# also: no need to test, if enabled
|
# also: no need to test, if enabled
|
||||||
[ -e '/var/etc/olsrd.conf' ] && {
|
[ -e '/var/etc/olsrd.conf' ] && {
|
||||||
olsrd_interface_needs_adding "$INTERFACE" "$DEVICE" && {
|
# INTERFACE = e.g. 'wlanadhocRADIO1' or 'cfg144d8f'
|
||||||
|
# DEVICE = e.g. 'wlan1-1'
|
||||||
|
olsrd_interface_needs_adding && {
|
||||||
. /etc/rc.common /etc/init.d/olsrd restart
|
. /etc/rc.common /etc/init.d/olsrd restart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue