[packages] ptunnel: Fix 'interface' option, handle multiple instances
authorVasilis Tsiligiannis <acinonyx@openwrt.gr>
Sat, 19 Sep 2009 13:23:26 +0000 (13:23 +0000)
committerVasilis Tsiligiannis <acinonyx@openwrt.gr>
Sat, 19 Sep 2009 13:23:26 +0000 (13:23 +0000)
SVN-Revision: 17608

net/ptunnel/files/ptunnel.conf
net/ptunnel/files/ptunnel.init

index ca645ff68d127fba37f11671527234741dfab5ca..bfc74959e799328efd5ca19cc273d7d77bbcb316 100644 (file)
@@ -1,2 +1,2 @@
 config ptunnel
-        option interface 'br-lan'
+       option interface 'lan'
index b3aabb9e155572757ce9420dabcec88204822254..99252d500dc65134ba6bb61713bca820f1cf42a6 100644 (file)
@@ -1,26 +1,40 @@
 #!/bin/sh /etc/rc.common
 # Copyright (C) 2007-2009 OpenWrt.org
+
 START=70
 BIN=ptunnel
+PIDCOUNT=0
 
 start() {
-    config_load ptunnel
-    config_foreach start_ptunnel ptunnel
+       include /lib/network
+       scan_interfaces
+
+       config_load ptunnel
+       config_foreach start_ptunnel ptunnel
+       iptables -I OUTPUT 1 -p icmp -j ACCEPT 2> /dev/null
 }
 
 start_ptunnel() {
-    local section="$1"
-    
-    include /lib/network
-    scan_interfaces
-    
-    iptables -I OUTPUT 1 -p icmp -j ACCEPT
-    config_get interface "$section" interface
-
-    $BIN -c "$interface" > /dev/null&
+       local section="$1"
+
+       config_get interface "$section" interface
+       config_get ifname "$interface" ifname
+
+       [ -z "$ifname" ] && {
+               echo "Error: Interface '$interface' not found" 1>&2
+               return 1
+       }
+
+       PIDCOUNT="$(( ${PIDCOUNT} + 1))"
+       ${BIN} -c "$ifname" -daemon /var/run/ptunnel."$PIDCOUNT".pid> /dev/null
 }
 
 stop() {
-        ps aux | grep ptunnel |  awk '{print }' | \
-            xargs kill 2> /dev/null
+       local pidfile
+
+       for pidfile in `ls /var/run/${BIN}.*.pid`
+       do
+               start-stop-daemon -K -s KILL -p "${pidfile}" -n "${BIN}" >/dev/null
+               rm -f "${pidfile}"
+       done
 }