2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2008-01-11 21:01:10 +05:30
|
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
_config_vars="$_config_vars plug_timeout"
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
ifplugd_depend()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
program start /usr/sbin/ifplugd
|
|
|
|
after macnet rename
|
|
|
|
before interface
|
|
|
|
provide plug
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
ifplugd_pre_start()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
local pidfile="/var/run/ifplugd.${IFACE}.pid" timeout= args=
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
# We don't start ifplugd if we're being called from the background
|
2007-11-22 18:58:14 +05:30
|
|
|
yesno ${IN_BACKGROUND} && return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
_exists || return 0
|
|
|
|
|
|
|
|
# We need a valid MAC address
|
|
|
|
# It's a basic test to ensure it's not a virtual interface
|
2007-11-28 21:15:03 +05:30
|
|
|
if ! _get_mac_address >/dev/null 2>&1; then
|
|
|
|
vewarn "ifplugd only works on interfaces with a valid MAC address"
|
2007-04-05 16:48:42 +05:30
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2010-11-19 02:36:42 +05:30
|
|
|
# We don't work on bonded, bridges, tun/tap, vlan or wireless
|
|
|
|
for f in bond bridge tuntap vlan wireless; do
|
2007-11-28 21:15:03 +05:30
|
|
|
if type "_is_${f}" >/dev/null 2>&1; then
|
|
|
|
if _is_${f}; then
|
2008-10-28 21:13:36 +05:30
|
|
|
veinfo "ifplugd does not work with ${f}"
|
2007-04-05 16:48:42 +05:30
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2008-10-28 21:13:36 +05:30
|
|
|
ebegin "Starting ifplugd on ${IFACE}"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
eval args=\$ifplugd_${IFVAR}
|
|
|
|
|
|
|
|
# Mark the us as inactive so netplug can restart us
|
2007-12-18 23:29:29 +05:30
|
|
|
mark_service_inactive
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Start ifplugd
|
|
|
|
eval start-stop-daemon --start --exec /usr/sbin/ifplugd \
|
|
|
|
--pidfile "${pidfile}" -- "${args}" --iface="${IFACE}"
|
2008-10-28 21:13:36 +05:30
|
|
|
eend $? || return 1
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
eindent
|
|
|
|
|
|
|
|
eval timeout=\$plug_timeout_${IFVAR}
|
|
|
|
[ -z "${timeout}" ] && timeout=-1
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ ${timeout} -eq 0 ]; then
|
|
|
|
ewarn "WARNING: infinite timeout set for ${IFACE} to come up"
|
|
|
|
elif [ ${timeout} -lt 0 ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
einfo "Backgrounding ..."
|
2011-01-17 15:19:07 +05:30
|
|
|
exit 1
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
veinfo "Waiting for ${IFACE} to be marked as started"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
local i=0
|
2007-11-28 21:15:03 +05:30
|
|
|
while true; do
|
2007-12-18 23:29:29 +05:30
|
|
|
if service_started; then
|
2007-04-05 16:48:42 +05:30
|
|
|
_show_address
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
sleep 1
|
2007-11-28 21:15:03 +05:30
|
|
|
[ ${timeout} -eq 0 ] && continue
|
2007-04-05 16:48:42 +05:30
|
|
|
i=$((${i} + 1))
|
|
|
|
[ ${i} -ge ${timeout} ] && break
|
|
|
|
done
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
eend 1 "Failed to configure ${IFACE} in the background"
|
2007-04-05 16:48:42 +05:30
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
ifplugd_stop()
|
|
|
|
{
|
2007-11-22 18:58:14 +05:30
|
|
|
yesno ${IN_BACKGROUND} && return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
local pidfile="/var/run/ifplugd.${IFACE}.pid"
|
|
|
|
[ ! -e "${pidfile}" ] && return 0
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2008-10-28 21:13:36 +05:30
|
|
|
ebegin "Stopping ifplugd on ${IFACE}"
|
2007-04-05 16:48:42 +05:30
|
|
|
start-stop-daemon --stop --quiet --exec /usr/sbin/ifplugd \
|
|
|
|
--pidfile "${pidfile}" --signal QUIT
|
|
|
|
eend $?
|
|
|
|
}
|