--- net.ppp0.orig 2003-08-16 22:06:01.000000000 +0200 +++ net.ppp0 2003-08-17 20:55:11.000000000 +0200 @@ -3,6 +3,7 @@ # Distributed under the terms of the GNU General Public License v2 # Author: Martin Schlemmer # Credits: To all those I got ideas from :) +# Modified by HS # # $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/net.ppp0,v 1.14 2003/05/18 21:51:34 azarah Exp $ @@ -25,7 +26,7 @@ if [ -e "/var/run/ppp-${IFACE}.pid" -o -e "/var/run/${IFACE}.pid" ] && \ [ "${FUNCT}" = "start" ] then - eerror "ppp0 is already up" + eerror "${IFACE} is already up" return 1 fi } @@ -61,23 +62,52 @@ if [ -x "$(which ifconfig)" ] then - if [ -z "$(/sbin/ifconfig | egrep "${IFACE}")" ] + # Obtain interface name from pid file (IFACE is actually linkname) + if [ -e /var/run/ppp-${IFACE}.pid ] + then + IFNAME=$(egrep "ppp" /var/run/ppp-${IFACE}.pid) + fi + if [ -z "${IFNAME}" ] then + IFNAME=${IFACE} + fi + + if [ -z "$(/sbin/ifconfig | egrep "${IFNAME}")" ] + then + + # Link is not up but pppd may be running ewarn "Interface seems to be down already" - # We should return 0 here, else svc_stop() will not remove - # the 'started' symlink ... - return 0 fi # /sbin/ifconfig ${IFACE} down if [ -e /var/run/ppp-${IFACE}.pid ] then - kill $(egrep -v "${IFACE}" /var/run/ppp-${IFACE}.pid) - + PID=$(egrep -v "${IFNAME}" /var/run/ppp-${IFACE}.pid) elif [ -e /var/run/${IFACE}.pid ] then - kill $(egrep -v "${IFACE}" /var/run/${IFACE}.pid) + PID=$(egrep -v "${IFNAME}" /var/run/${IFACE}.pid) fi + + kill ${PID} + + # Check if pppd is not running (check it 10 times because pppd + # sometimes do not finish so fast) + PID=`pstree -p ${PID} | sed -e 's:^.*pppd::'` + PID=${PID:1:${#PID}-2} + COUNT=0 + while [ -n "${PID}" ] && [ ${COUNT} -lt 10 ] + do + sleep 0.5 + PID=`pstree -p ${PID} | sed -e 's:^.*pppd::'` + PID=${PID:1:${#PID}-2} + let COUNT++ + done + + if [ -n "${PID}" ] + then + eend 1 "Error stopping pppd" + fi + fi eend } @@ -163,16 +193,19 @@ chmod 600 /etc/ppp/pap-secrets # Setup the chat file - if [ -n "${INITSTRING}" ] + if [ "${AUTOCHATSCRIPT}" = "yes" ] then - sed -e "9i\\'OK\' \'${INITSTRING}\'" \ - -e "s:\$NUMBER:${NUMBER}:" \ - ${TEMPLATEDIR}/chat-default \ - >/etc/ppp/chat-${PEER} - else - sed -e "s:\$NUMBER:${NUMBER}:" \ - ${TEMPLATEDIR}/chat-default \ - >/etc/ppp/chat-${PEER} + if [ -n "${INITSTRING}" ] + then + sed -e "9i\\'OK\' \'${INITSTRING}\'" \ + -e "s:\$NUMBER:${NUMBER}:" \ + ${TEMPLATEDIR}/chat-default \ + >/etc/ppp/chat-${PEER} + else + sed -e "s:\$NUMBER:${NUMBER}:" \ + ${TEMPLATEDIR}/chat-default \ + >/etc/ppp/chat-${PEER} + fi fi # Setup the ip-scripts so long