#!/bin/sh
#
#	$Id: ifdown-ppp 6491 2005-10-26 16:33:29Z baggins $
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /etc/sysconfig/network
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network-scripts/functions.network

CONFIG=$1
source_config

if [ ! -f /var/run/ppp-$DEVNAME.pid ]; then
	# ppp isn't running, or we didn't start it
	exit 0
fi

# set all major variables
setup_ip_param
get_ppp_device_and_pid

if [ -z "$PID" ]; then
	exit 1
fi

rm -f /var/run/ppp-$DEVNAME.pid

[ ! -d /proc/${PID} ] && exit 0

kill -TERM ${PID} > /dev/null 2>&1

sleep 2
[ -d /proc/${PID} ] && sleep 2 && [ -d /proc/${PID} ] && sleep 5

kill -KILL ${PID} > /dev/null 2>&1
logger -p daemon.info -t ifdown-ppp "ifdown-ppp unable to nicely kill pppd-$DEVICE (pppd-$DEVNAME)" &

# Special cases
if is_yes "${PPPOA_EAGLE}"; then
	EAGLECTRL="/usr/sbin/adictrl"
	if [ ! -x $EAGLECTRL ]; then
		EAGLECTRL="/usr/sbin/eaglectrl"
	fi
	if [ -x $EAGLECTRL ]; then
		PPPOA_IFACE=$( $EAGLECTRL -i 2>/dev/null)
		[ -n "$PPPOA_IFACE" ] && ip link set "$PPPOA_IFACE" down
	fi
fi

/etc/sysconfig/network-scripts/ifdown-post $1

exit 1

# This must be last line !
# vi:syntax=sh
