#!/bin/bash
# Based on Red Hat's ppp scripts
# MSG - yinyang@eburg.com
# 06/28/2000
PATH=/sbin:/usr/sbin:/bin:/usr/bin

cd /etc/sysconfig/network-scripts
. network-functions

CONFIG=$1
source_config

file=/var/run/ppp-$DEVICE.pid

if [ ! -f $file ]; then
       # ppp isn't running, or we didn't start it
       exit 0
fi

# remove the "$DEVICE-up" file so ifup-vpn knows to quit
if [ "${PERSIST}" = yes ] ; then
       vpnfile=/var/run/${DEVICE}-up
       [ -f "$vpnfile" ] && rm -f "$vpnfile"
fi

# pppd appears to put its pid and the real device name in this file
PID=`head -1 $file`
[ -n "$PID" ] || exit 1

kill -TERM $PID > /dev/null 2>&1
# Give pppd a chance to exit
sleep 1
[ ! -d /proc/$PID ] && exit 0
sleep 2
[ ! -d /proc/$PID ] && exit 0

# killing ppp-watch twice in a row causes it to send a SIGKILL to pppd pgrp
kill -TERM $PID > /dev/null 2>&1
# ip-down won't run in this case
/etc/sysconfig/network-scripts/ifdown-post $1
[ ! -d /proc/$PID ] && exit 0

exit 1
