From 1fd3f85d4fbcacd817383df479c5674c4ff13e3e Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 8 May 2017 11:43:27 +0200 Subject: [PATCH 1/4] 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 --- net/mwan3/files/lib/mwan3/mwan3.sh | 20 ++++++-------------- net/mwan3/files/usr/libexec/rpcd/mwan3 | 12 ++++-------- net/mwan3/files/usr/sbin/mwan3 | 4 +--- net/mwan3/files/usr/sbin/mwan3track | 7 +++---- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index f0ebcc42e..561aaede6 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -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 } diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index 028dafe1d..2b8046068 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -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}" diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index 63617316c..10dc86f8f 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -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() diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 0d7b5ab5d..58a31f0ca 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -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 From ef3261d0b46be45d8268f101c7c0b7eb763d4b6b Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 12 May 2017 15:24:05 +0200 Subject: [PATCH 2/4] net/mwan3: remove absolute path for bin files Signed-off-by: Florian Eckert --- net/mwan3/files/etc/hotplug.d/iface/15-mwan3 | 6 ------ net/mwan3/files/lib/mwan3/mwan3.sh | 12 ++++++------ net/mwan3/files/usr/libexec/rpcd/mwan3 | 6 +++--- net/mwan3/files/usr/sbin/mwan3 | 6 ------ net/mwan3/files/usr/sbin/mwan3track | 2 +- 5 files changed, 10 insertions(+), 22 deletions(-) diff --git a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 index a13ff8324..e3fd16cef 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 @@ -11,12 +11,6 @@ if [ "$ACTION" == "ifup" ]; then [ -n "$DEVICE" ] || exit 3 fi -[ -x /usr/bin/ip ] || exit 4 -[ -x /usr/sbin/ipset ] || exit 5 -[ -x /usr/sbin/iptables ] || exit 6 -[ -x /usr/sbin/ip6tables ] || exit 7 -[ -x /usr/bin/logger ] || exit 8 - mwan3_set_connected_iptables config_load mwan3 diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 561aaede6..3798d7eb0 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -1,11 +1,11 @@ #!/bin/sh -IP4="/usr/bin/ip -4" -IP6="/usr/bin/ip -6" -IPS="/usr/sbin/ipset" -IPT4="/usr/sbin/iptables -t mangle -w" -IPT6="/usr/sbin/ip6tables -t mangle -w" -LOG="/usr/bin/logger -t mwan3 -p" +IP4="ip -4" +IP6="ip -6" +IPS="ipset" +IPT4="iptables -t mangle -w" +IPT6="ip6tables -t mangle -w" +LOG="logger -t mwan3 -p" CONNTRACK_FILE="/proc/net/nf_conntrack" mwan3_get_iface_id() diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index 2b8046068..bbc570f6c 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -6,9 +6,9 @@ MWAN3_STATUS_DIR="/var/run/mwan3track" MWAN3_PID_FILE="/var/run/mwan3track" -IPS="/usr/sbin/ipset" -IPT4="/usr/sbin/iptables -t mangle -w" -IPT6="/usr/sbin/ip6tables -t mangle -w" +IPS="ipset" +IPT4="iptables -t mangle -w" +IPT6="ip6tables -t mangle -w" report_connected_v4() { local address diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index 10dc86f8f..f23d2e71b 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -1,11 +1,5 @@ #!/bin/sh -[ -x /usr/bin/ip ] || exit 4 -[ -x /usr/sbin/ipset ] || exit 5 -[ -x /usr/sbin/iptables ] || exit 6 -[ -x /usr/sbin/ip6tables ] || exit 7 -[ -x /usr/bin/logger ] || exit 8 - . /lib/functions.sh . /lib/functions/network.sh . /lib/mwan3/mwan3.sh diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 58a31f0ca..8179a9e51 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -2,7 +2,7 @@ . /lib/functions.sh -LOG="/usr/bin/logger -t $(basename "$0")[$$] -p" +LOG="logger -t $(basename "$0")[$$] -p" INTERFACE="" DEVICE="" From db5ea39c9bf6afdece076e4eff4ebdf8b6138497 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 12 May 2017 15:30:14 +0200 Subject: [PATCH 3/4] net/mwan3: generate mwan3track run path folder on every run Signed-off-by: Florian Eckert --- net/mwan3/files/usr/sbin/mwan3track | 1 + 1 file changed, 1 insertion(+) diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 8179a9e51..8afe90129 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -109,6 +109,7 @@ main() { fi let turn++ + mkdir -p "/var/run/mwan3track/${1}" echo "${lost}" > /var/run/mwan3track/$1/LOST echo "${score}" > /var/run/mwan3track/$1/SCORE echo "${turn}" > /var/run/mwan3track/$1/TURN From f35475c0255176449310db48914a8b19176eaf3d Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 12 May 2017 15:25:18 +0200 Subject: [PATCH 4/4] net/mwan3: update Makefile version Signed-off-by: Florian Eckert --- net/mwan3/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 4a0856edc..394a642f9 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.5.1 +PKG_VERSION:=2.5.2 PKG_RELEASE:=5 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPLv2