net/mwan3: fix mwan3track kill execution

If two interface have the same prefix "wan" for example "wan" and "wan1"
pgrep returns the PID for wan1 also "pgrep -f mwan3track wan".

Before this fix "wan1" was also killed! This is not what we want.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert 2017-07-31 11:46:21 +02:00
parent 487278dcd1
commit 0b44ca505b
4 changed files with 10 additions and 7 deletions

View file

@ -449,7 +449,7 @@ mwan3_track()
}
config_list_foreach $1 track_ip mwan3_list_track_ips
kill $(pgrep -f "mwan3track $1") &> /dev/null
kill $(pgrep -f "mwan3track $1 $2") &> /dev/null
if [ -n "$track_ips" ]; then
[ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track "$1" "$2" "$3" $track_ips &
fi
@ -459,7 +459,7 @@ mwan3_track_signal()
{
local pid
pid="$(pgrep -f "mwan3track $1")"
pid="$(pgrep -f "mwan3track $1 $2")"
if [ "${pid}" != "" ]; then
kill -USR1 "${pid}"
else
@ -789,7 +789,7 @@ mwan3_report_iface_status()
config_list_foreach $1 track_ip mwan3_list_track_ips
if [ -n "$track_ips" ]; then
if [ -n "$(pgrep -f "mwan3track $1")" ]; then
if [ -n "$(pgrep -f "mwan3track $1 $device")" ]; then
tracking="active"
else
tracking="down"

View file

@ -1,6 +1,7 @@
#!/bin/sh
. /lib/functions.sh
. /lib/functions/network.sh
. /usr/share/libubox/jshn.sh
MWAN3_STATUS_DIR="/var/run/mwan3track"
@ -34,10 +35,12 @@ get_mwan3_status() {
local iface="${1}"
local iface_select="${2}"
local running="0"
local pid
local pid device
network_get_device device $1
if [ "${iface}" = "${iface_select}" ] || [ "${iface_select}" = "" ]; then
pid="$(pgrep -f "mwan3track $iface")"
pid="$(pgrep -f "mwan3track $iface $device")"
if [ "${pid}" != "" ]; then
running="1"
fi

View file

@ -36,7 +36,7 @@ ifdown()
ACTION=ifdown INTERFACE=$1 /sbin/hotplug-call iface
kill $(pgrep -f "mwan3track $1") &> /dev/null
kill $(pgrep -f "mwan3track $1 $2") &> /dev/null
}
ifup()

View file

@ -10,7 +10,7 @@ IFDOWN_EVENT=0
clean_up() {
$LOG notice "Stopping mwan3track for interface \"${INTERFACE}\""
if [ "$(pgrep -f "mwan3track ${INTERFACE}")" = "" ]; then
if [ "$(pgrep -f "mwan3track ${INTERFACE} ${DEVICE}")" = "" ]; then
rm -rf "/var/run/mwan3track/${INTERFACE}" &> /dev/null
fi
if [ -z "$(ls -A "/var/run/mwan3track")" ]; then