package/ppp: use new service wrappers
[openwrt.git] / package / ppp / files / ppp.sh
index 42daef9..77f5b0e 100644 (file)
@@ -4,19 +4,11 @@ stop_interface_ppp() {
        local proto
        config_get proto "$cfg" proto
 
        local proto
        config_get proto "$cfg" proto
 
-       local ifname
-       config_get ifname "$cfg" ifname
-
-       local link="$proto-${ifname#$proto-}"
-       [ -f "/var/run/ppp-${link}.pid" ] && {
-               local pid="$(head -n1 /var/run/ppp-${link}.pid 2>/dev/null)"
-               local try=0
-               grep -qs pppd "/proc/$pid/cmdline" && kill -TERM $pid && \
-                       while grep -qs pppd "/proc/$pid/cmdline" && [ $((try++)) -lt 5 ]; do sleep 1; done
-               grep -qs pppd "/proc/$pid/cmdline" && kill -KILL $pid && \
-                       while grep -qs pppd "/proc/$pid/cmdline"; do sleep 1; done
-               rm -f "/var/run/ppp-${link}.pid"
-       }
+       local link="$proto-$cfg"
+       SERVICE_PID_FILE="/var/run/ppp-${link}.pid" \
+       service_stop /usr/sbin/pppd
+
+       remove_dns "$cfg"
 
        local lock="/var/lock/ppp-$link"
        [ -f "$lock" ] && lock -u "$lock"
 
        local lock="/var/lock/ppp-$link"
        [ -f "$lock" ] && lock -u "$lock"
@@ -25,6 +17,13 @@ stop_interface_ppp() {
 start_pppd() {
        local cfg="$1"; shift
 
 start_pppd() {
        local cfg="$1"; shift
 
+       # Workaround for PPPoE service and AC name options,
+       # filter out the nic-* argument and append it as last option
+       local nic=""
+       case "$1" in
+               nic-*) nic="$1"; shift ;;
+       esac
+
        local proto
        config_get proto "$cfg" proto
 
        local proto
        config_get proto "$cfg" proto
 
@@ -33,8 +32,8 @@ start_pppd() {
 
        # make sure only one pppd process is started
        lock "/var/lock/ppp-${link}"
 
        # make sure only one pppd process is started
        lock "/var/lock/ppp-${link}"
-       local pid="$(head -n1 /var/run/ppp-${link}.pid 2>/dev/null)"
-       [ -d "/proc/$pid" ] && grep pppd "/proc/$pid/cmdline" 2>/dev/null >/dev/null && {
+       SERVICE_PID_FILE="/var/run/ppp-${link}.pid" \
+       service_check /usr/sbin/ppd && {
                lock -u "/var/lock/ppp-${link}"
                return 0
        }
                lock -u "/var/lock/ppp-${link}"
                return 0
        }
@@ -85,27 +84,20 @@ start_pppd() {
        local peerdns
        config_get_bool peerdns "$cfg" peerdns $peer_default
 
        local peerdns
        config_get_bool peerdns "$cfg" peerdns $peer_default
 
-       if [ "$peerdns" -eq 1 ] || [ ! -e /tmp/resolv.conf.auto ]; then
-               echo -n "" > /tmp/resolv.conf.auto
-       fi
-
        [ "$peerdns" -eq 1 ] && {
                peerdns="usepeerdns"
        } || {
                peerdns=""
        [ "$peerdns" -eq 1 ] && {
                peerdns="usepeerdns"
        } || {
                peerdns=""
-               for dns in $dns; do
-                       echo "nameserver $dns" >> /tmp/resolv.conf.auto
-               done
+               add_dns "$cfg" $dns
        }
 
        local demand
        }
 
        local demand
-       config_get_bool demand "$cfg" demand 0
+       config_get demand "$cfg" demand 0
 
        local demandargs
 
        local demandargs
-       [ "$demand" -eq 1 ] && {
-               demandargs="precompiled-active-filter /etc/ppp/filter demand idle"
-               [ "$has_dns" -eq 0 ] && \
-                       echo "nameserver 1.1.1.1" > /tmp/resolv.conf.auto
+       [ "$demand" -gt 0 ] && {
+               demandargs="precompiled-active-filter /etc/ppp/filter demand idle $demand"
+               [ "$has_dns" -eq 0 ] && add_dns "$cfg" 1.1.1.1
        } || {
                demandargs="persist"
        }
        } || {
                demandargs="persist"
        }
@@ -114,7 +106,10 @@ start_pppd() {
        config_get_bool ipv6 "$cfg" ipv6 0
        [ "$ipv6" -eq 1 ] && ipv6="+ipv6" || ipv6=""
 
        config_get_bool ipv6 "$cfg" ipv6 0
        [ "$ipv6" -eq 1 ] && ipv6="+ipv6" || ipv6=""
 
-       start-stop-daemon -S -b -x /usr/sbin/pppd -m -p /var/run/ppp-$link.pid -- "$@" \
+       SERVICE_DAEMONIZE=1 \
+       SERVICE_WRITE_PID=1 \
+       SERVICE_PID_FILE="/var/run/ppp-$link.pid" \
+       service_start /usr/sbin/pppd "$@" \
                ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
                $demandargs \
                $peerdns \
                ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
                $demandargs \
                $peerdns \
@@ -126,7 +121,8 @@ start_pppd() {
                ${disconnect:+disconnect "$disconnect"} \
                ${ipv6} \
                ${pppd_options} \
                ${disconnect:+disconnect "$disconnect"} \
                ${ipv6} \
                ${pppd_options} \
-               nodetach
+               nodetach \
+               ${nic}
 
        lock -u "/var/lock/ppp-${link}"
 }
 
        lock -u "/var/lock/ppp-${link}"
 }
This page took 0.024679 seconds and 4 git commands to generate.