net/mwan3: add clean_up trap function for SIGINT SIGTERM
authorFlorian Eckert <fe@dev.tdt.de>
Tue, 4 Apr 2017 14:00:06 +0000 (16:00 +0200)
committerFlorian Eckert <fe@dev.tdt.de>
Tue, 4 Apr 2017 14:00:06 +0000 (16:00 +0200)
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
net/mwan3/files/lib/mwan3/mwan3.sh
net/mwan3/files/usr/sbin/mwan3
net/mwan3/files/usr/sbin/mwan3track

index c3af635837a2618181ac48bfaec86df40d566b9a..56b9ce633f2ff2683f43f706e6fb69962100c48a 100644 (file)
@@ -393,7 +393,6 @@ mwan3_track()
 
        if [ -e /var/run/mwan3track-$1.pid ] ; then
                kill $(cat /var/run/mwan3track-$1.pid) &> /dev/null
-               rm /var/run/mwan3track-$1.pid &> /dev/null
        fi
 
        if [ -n "$track_ips" ]; then
index 405cd43f3fdf5c019c802c31691a1dfac5474a62..63617316cb2d8ed6b92ee7b732981787f6e45f5b 100755 (executable)
@@ -44,7 +44,6 @@ ifdown()
 
        if [ -e /var/run/mwan3track-$1.pid ] ; then
                kill $(cat /var/run/mwan3track-$1.pid)
-               rm /var/run/mwan3track-$1.pid
        fi
 }
 
@@ -129,7 +128,6 @@ stop()
        local ipset route rule table IP IPT
 
        killall mwan3track &> /dev/null
-       rm /var/run/mwan3track-* &> /dev/null
 
        for IP in "$IP4" "$IP6"; do
 
index c2a69927295114ee74353cb0736b4d255a9d3807..6bfdaa0a71ceb19f2de07b0cd6726a4210a2feea 100755 (executable)
@@ -1,17 +1,21 @@
 #!/bin/sh
 
 LOG="/usr/bin/logger -t $(basename "$0")[$$] -p"
+INTERFACE=""
+
+clean_up() {
+       $LOG notice "Stopping mwan3track for interface \"${INTERFACE}\""
+       rm "/var/run/mwan3track-${INTERFACE}.pid" &> /dev/null
+       exit 0
+}
 
 main() {
 
        [ -z "$12" ] && echo "Error: should not be started manually" && exit 0
 
-       if [ -e /var/run/mwan3track-$1.pid ] ; then
-               kill $(cat /var/run/mwan3track-$1.pid) &> /dev/null
-               rm /var/run/mwan3track-$1.pid &> /dev/null
-       fi
-
+       INTERFACE=$1
        echo "$$" > /var/run/mwan3track-$1.pid
+       trap clean_up SIGINT SIGTERM
 
        local score=$(($7+$8))
        local track_ips=$(echo $* | cut -d ' ' -f 12-99)