#!/sbin/runscript # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/sys-apps/ifplugd/files/gentoo-ifplugd-init-v3,v 1.4 2005/04/09 16:20:56 ka0ttic Exp $ #NB: Config is in /etc/conf.d/ifplugd opts="stop start status suspend resume" IFPLUGD=/usr/sbin/ifplugd [ -z "$INTERFACES" ] && INTERFACES="eth0" [ "$INTERFACES" = "auto" ] && INTERFACES=$(sed -ne 's/.*\<\(eth[0-9]*\):.*/\1/p' /proc/net/dev) # Check if an option is set for a given interface. # $1 is interface, $2 is option name, $3 is preset is_set() { [ "$(get_opt "$@")" = "yes" ] } # Expand an option value for a given interface. # $1 is interface, $2 is option name, $3 is preset get_opt() { local iface=$1 option=$2 preset=$3 eval preset=\${${option}:=${preset}} eval echo \${${option}_${iface}:=${preset}} } check_success() { local iface=$1 action=$2 status=$3 if [ "${action}" = "start" ] && is_set ${iface} WAIT_ON_FORK yes; then [ ${status} -le 2 ] else [ ${status} ] fi } # Handle starting for all interfaces # $1 is deamon args, $2 is action name do_all_if() { local dargs=$1 action=$2 IF args status for IF in ${INTERFACES}; do iargs= is_set ${IF} AUTO yes || iargs="${iargs}a" is_set ${IF} BEEP yes || iargs="${iargs}b" is_set ${IF} IGNORE_FAIL yes && iargs="${iargs}f" is_set ${IF} IGNORE_FAIL_POSITIVE no && iargs="${iargs}F" is_set ${IF} IGNORE_RETVAL yes && iargs="${iargs}I" is_set ${IF} SHUTDOWN yes || iargs="${iargs}q" is_set ${IF} WAIT_ON_FORK yes && iargs="${iargs}w" is_set ${IF} MONITOR no && iargs="${iargs}M" [ -n "${iargs}" ] && iargs="-${iargs}" iargs="${iargs} -t$(get_opt ${IF} POLL_TIME 1)" iargs="${iargs} -u$(get_opt ${IF} DELAY_UP 0)" iargs="${iargs} -d$(get_opt ${IF} DELAY_DOWN 5)" iargs="${iargs} -m$(get_opt ${IF} API_MODE auto)" iargs="${iargs} $(get_opt ${IF} ARGS '')" echo -n "${IF} " ${IFPLUGD} ${dargs} --iface=${IF} ${iargs} check_success ${IF} ${action} $? status=$? [ $status ] || break done echo eend $status "Couldn't ${action} ifplugd for ${IF}" } depend() { use pcmcia } start() { einfon "Starting ifplugd: " do_all_if "" start } stop() { einfon "Stopping ifplugd: " do_all_if -k stop # Now we have to wait until it's actually down local i=10 while [ $i -gt 0 ] && status | grep -q "running as"; do i=$(( $i - 1 )) sleep 1 done if [ $i -eq 0 ]; then eend 1 "Timeout exceeded, ifplugd won't die!" fi } status() { do_all_if -c "get status from" } suspend() { einfon "Suspending ifplugd: " do_all_if -S suspend } resume() { einfon "Resuming ifplugd: " do_all_if -R resume } # vim:ts=4