Browse Source

net/mwan3: remove pid file use pgrep to get pid

If mwan3track will not stop immediately after sending the kill signal,
the clean_up handler will delete the pid file later while the new mwan3track is
already running.

This could result in a situation that mwan3track is running
more then once because the old mwan3track service could not be killed,
because the pid file is missing.

Using pgrep to kill all mwan3track for the tracked interface and not using
pid file should fix this issue.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
lilik-openwrt-22.03
Florian Eckert 8 years ago
parent
commit
1fd3f85d4f
4 changed files with 14 additions and 29 deletions
  1. +6
    -14
      net/mwan3/files/lib/mwan3/mwan3.sh
  2. +4
    -8
      net/mwan3/files/usr/libexec/rpcd/mwan3
  3. +1
    -3
      net/mwan3/files/usr/sbin/mwan3
  4. +3
    -4
      net/mwan3/files/usr/sbin/mwan3track

+ 6
- 14
net/mwan3/files/lib/mwan3/mwan3.sh View File

@ -390,10 +390,7 @@ mwan3_track()
}
config_list_foreach $1 track_ip mwan3_list_track_ips
if [ -e /var/run/mwan3track-$1.pid ] ; then
kill $(cat /var/run/mwan3track-$1.pid) &> /dev/null
fi
kill $(pgrep -f "mwan3track $1") &> /dev/null
if [ -n "$track_ips" ]; then
[ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track $1 $2 $track_ips &
fi
@ -401,18 +398,13 @@ mwan3_track()
mwan3_track_signal()
{
local pid status
local pid
if [ -f "/var/run/mwan3track-${1}.pid" ]; then
pid="$(cat "/var/run/mwan3track-${1}.pid")"
status="$(pgrep -f mwan3track | grep "${pid}")"
if [ "${status}" != "" ]; then
kill -USR1 "${pid}"
else
$LOG warn "Unable to send signal USR1 to mwan3track on interface $1 with pid ${pid}"
fi
pid="$(pgrep -f "mwan3track $1")"
if [ "${pid}" != "" ]; then
kill -USR1 "${pid}"
else
$LOG warn "Unable to find \"/var/run/mwan3track-${1}.pid\" file for mwan3track on interface $1"
$LOG warn "Unable to send signal USR1 to mwan3track on interface $1 with pid ${pid}"
fi
}


+ 4
- 8
net/mwan3/files/usr/libexec/rpcd/mwan3 View File

@ -34,16 +34,12 @@ get_mwan3_status() {
local iface="${1}"
local iface_select="${2}"
local running="0"
local pid=""
local status=""
local pid
if [ "${iface}" = "${iface_select}" ] || [ "${iface_select}" = "" ]; then
if [ -f "${MWAN3_PID_FILE}-${iface}.pid" ]; then
pid="$(cat "${MWAN3_PID_FILE}-${iface}.pid")"
status="$(pgrep -f mwan3track | grep "${pid}")"
if [ "${status}" != "" ]; then
running="1"
fi
pid="$(pgrep -f "mwan3track $iface_selected")"
if [ "${pid}" != "" ]; then
running="1"
fi
json_add_object "${iface}"


+ 1
- 3
net/mwan3/files/usr/sbin/mwan3 View File

@ -42,9 +42,7 @@ ifdown()
ACTION=ifdown INTERFACE=$1 /sbin/hotplug-call iface
if [ -e /var/run/mwan3track-$1.pid ] ; then
kill $(cat /var/run/mwan3track-$1.pid)
fi
kill $(pgrep -f "mwan3track $1") &> /dev/null
}
ifup()


+ 3
- 4
net/mwan3/files/usr/sbin/mwan3track View File

@ -10,8 +10,9 @@ IFDOWN_EVENT=0
clean_up() {
$LOG notice "Stopping mwan3track for interface \"${INTERFACE}\""
rm "/var/run/mwan3track-${INTERFACE}.pid" &> /dev/null
rm -rf "/var/run/mwan3track/${INTERFACE}" &> /dev/null
if [ "$(pgrep -f "mwan3track ${INTERFACE}")" = "" ]; then
rm -rf "/var/run/mwan3track/${INTERFACE}" &> /dev/null
fi
if [ -z "$(ls -A "/var/run/mwan3track")" ]; then
rm -rf "/var/run/mwan3track"
fi
@ -31,7 +32,6 @@ main() {
INTERFACE=$1
DEVICE=$2
echo "$$" > /var/run/mwan3track-$1.pid
mkdir -p /var/run/mwan3track/$1
trap clean_up SIGINT SIGTERM
trap if_down SIGUSR1
@ -103,7 +103,6 @@ main() {
if [ $score -eq $up ]; then
$LOG notice "Interface $1 ($2) is online"
env -i ACTION=ifup INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
rm /var/run/mwan3track-$1.pid
rm -rf "/var/run/mwan3track/${1}" &> /dev/null
exit 0
fi


Loading…
Cancel
Save