Replace locks on /var/run/mwan3.lock with locks via procd.
This fixes a deadlock issue where mwan3 stop would have a procd
lock, but a hotplug script would have the /var/run/mwan3.lock
Locking can be removed from mwan3rtmon since:
1) procd will have sent the KILL signal to the process during
shutdown, so it will not add routes to already removed interfaces on
mwan3 shutdown and
2) mwan3rtmon checks if an interface is active based on the
mwan3_iface_in_<IFACE> entry in iptables, and the hotplug script
always adds this before creating the route table and removes it
before deleting the route table
Fixes github issue #13704
(https://github.com/openwrt/packages/issues/13704)
. /lib/mwan3/mwan3.sh
. /lib/mwan3/common.sh
+initscript=/etc/init.d/mwan3
+. /lib/functions/procd.sh
+
+
SCRIPTNAME="mwan3-hotplug"
[ "$ACTION" = "ifup" ] || [ "$ACTION" = "ifdown" ] || [ "$ACTION" = "connected" ] || [ "$ACTION" = "disconnected" ] || exit 1
[ -n "$INTERFACE" ] || exit 2
exit 3
fi
-[ "$MWAN3_STARTUP" = 1 ] || mwan3_lock "$ACTION" "$INTERFACE"
+[ "$MWAN3_STARTUP" = 1 ] || procd_lock
config_load mwan3
/etc/init.d/mwan3 running || {
- [ "$MWAN3_STARTUP" = 1 ] || mwan3_unlock "$ACTION" "$INTERFACE"
+ [ "$MWAN3_STARTUP" = 1 ] || procd_lock
LOG notice "mwan3 hotplug $ACTION on $INTERFACE not called because globally disabled"
mwan3_flush_conntrack "$INTERFACE" "$ACTION"
exit 0
}
$IPT4 -S mwan3_hook &>/dev/null || {
- mwan3_unlock "$ACTION" "$INTERFACE"
LOG warn "hotplug called on $INTERFACE before mwan3 has been set up"
exit 0
}
config_get_bool enabled $INTERFACE 'enabled' '0'
[ "${enabled}" -eq 1 ] || {
- [ "$MWAN3_STARTUP" = 1 ] || mwan3_unlock "$ACTION" "$INTERFACE"
LOG notice "mwan3 hotplug on $INTERFACE not called because interface disabled"
exit 0
}
status=online
fi
-if [ "$ACTION" = ifup ] || [ "$ACTION" = ifdown ]; then
- initscript=/etc/init.d/mwan3
- . /lib/functions/procd.sh
-fi
-
LOG notice "Execute $ACTION event on interface $INTERFACE (${DEVICE:-unknown})"
case "$ACTION" in
mwan3_set_policies_iptables
;;
esac
-[ "$MWAN3_STARTUP" = 1 ] || mwan3_unlock "$ACTION" "$INTERFACE"
exit 0
[ -f "/etc/mwan3.user" ] && {
. /lib/functions.sh
. /lib/mwan3/mwan3.sh
+ initscript=/etc/init.d/mwan3
+ . /lib/functions/procd.sh
- [ "$MWAN3_SHUTDOWN" != 1 ] && mwan3_lock "$ACTION" "$DEVICE-user"
+ [ "$MWAN3_SHUTDOWN" != 1 ] && procd_lock
[ "$MWAN3_SHUTDOWN" != 1 ] && ! /etc/init.d/mwan3 running && {
- mwan3_unlock "$ACTION" "$DEVICE-user"
exit 0
}
exit 0
}
- [ "$MWAN3_SHUTDOWN" != 1 ] && mwan3_unlock "$ACTION" "$DEVICE-user"
-
env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \
/bin/sh /etc/mwan3.user
}
mwan3_init
config_foreach start_tracker interface
- mwan3_lock "command" "mwan3"
-
mwan3_update_iface_to_table
mwan3_set_connected_ipset
mwan3_set_custom_ipset
mwan3_set_policies_iptables
mwan3_set_user_rules
- mwan3_unlock "command" "mwan3"
-
procd_open_instance rtmon_ipv4
procd_set_param command /usr/sbin/mwan3rtmon ipv4
procd_set_param respawn
stop_service() {
local ipset rule IP IPTR IPT family table tid
- mwan3_lock "command" "mwan3"
-
config_load mwan3
mwan3_init
config_foreach mwan3_interface_shutdown interface
rm -rf $MWAN3_STATUS_DIR $MWAN3TRACK_STATUS_DIR
- mwan3_unlock "command" "mwan3"
}
reload_service() {
echo $count
}
-mwan3_lock() {
- lock /var/run/mwan3.lock
- #LOG debug "$1 $2 (lock)"
-}
-
-mwan3_unlock() {
- #LOG debug "$1 $2 (unlock)"
- lock -u /var/run/mwan3.lock
-}
-
mwan3_get_iface_id()
{
local _tmp
IP="$IP4"
fi
mwan3_init
- mwan3_lock "mwan3rtmon" "start"
sh -c "echo \$\$; exec $IP monitor route" | {
read -r monitor_pid
trap_with_arg func_trap "$monitor_pid" SIGINT SIGTERM SIGKILL
while IFS='' read -r line; do
[ -z "${line##*table*}" ] && continue
LOG debug "handling route update $family '$line'"
- mwan3_lock "service" "mwan3rtmon"
mwan3_rtmon_route_handle "$line" "$family"
- mwan3_unlock "service" "mwan3rtmon"
done
} &
child=$!
trap_with_arg func_trap "$child" SIGINT SIGTERM SIGKILL
mwan3_set_connected_${family}
mwan3_add_all_routes ${family}
- mwan3_unlock "mwan3rtmon" "start"
kill -SIGCONT $child
wait $!
}