#!/bin/sh
#
#	$Id: ifdown-sl,v 1.9 1999/10/13 21:28:40 kloczek Exp $
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin

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

CONFIG=$1
source_config

# signals ifup-sl not to persist
rm -f /var/run/sl-$DEVICE.dev

# we can use dip or direct slip connection via slattach
if [ "$DIRECT_CONNECT" != "yes" ]; then
PID=`pidof dip-$DEVICE`
else
PID=`pidof slattach`
for x in $PID; do
	if grep -q "$MODEMPORT" /proc/$x/cmdline; then
	logger -p daemon.info -t ifdown-sl "signal TERM send to \"`ps -o cmd= $x`\" - this should be slattach"
	kill -TERM $x
	PID=$x
	fi
done
fi
#
# The proctitle for connected dip daemons is actually "-dip (ipaddr)"
#	with ipaddr = local on dial-out,  remote on dial-in
# Grab the PID of connected dial-out daemon.
#
if [ -z "$PID" ]; then
  PID=`pidof -- -dip\ \($IPADDR\)`
fi
if [ -z "$PID" ]; then
  exit 1
fi

kill $PID > /dev/null 2>&1
if [ ! -d /proc/$PID ]; then
  /etc/sysconfig/network-scripts/ifdown-post $1
  exit 0
fi
sleep 2
if [ ! -d /proc/$PID ]; then
  /etc/sysconfig/network-scripts/ifdown-post $1
  exit 0
fi

kill -KILL $PID > /dev/null 2>&1
if [ -d /proc/$PID ]; then
  logger -p daemon.info -t ifdown-ppp "ifdown-ppp unable to kill pppd-$DEVICE" &
else
  /etc/sysconfig/network-scripts/ifdown-post $1
fi

exit 1

