From 8b23aaecff11723184bc4761bef68ed98a3ad7af Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 10 Mar 2008 21:34:46 +0000 Subject: Add ifwatchd.sh to power the NetBSD ifwatchd program. Let wpa_supplicant work with it. --- net.NetBSD/Makefile | 5 ++++ net.NetBSD/ifwatchd.sh | 60 ++++++++++++++++++++++++++++++++++++++ net/wpa_supplicant.sh | 18 +++++++----- sh.NetBSD/.gitignore | 2 ++ sh.NetBSD/Makefile | 6 ++++ sh.NetBSD/ifwatchd-carrier.sh.in | 5 ++++ sh.NetBSD/ifwatchd-nocarrier.sh.in | 5 ++++ 7 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 net.NetBSD/Makefile create mode 100644 net.NetBSD/ifwatchd.sh create mode 100644 sh.NetBSD/.gitignore create mode 100644 sh.NetBSD/Makefile create mode 100644 sh.NetBSD/ifwatchd-carrier.sh.in create mode 100644 sh.NetBSD/ifwatchd-nocarrier.sh.in diff --git a/net.NetBSD/Makefile b/net.NetBSD/Makefile new file mode 100644 index 00000000..ebdb26f2 --- /dev/null +++ b/net.NetBSD/Makefile @@ -0,0 +1,5 @@ +DIR= ${RC_LIB}/net +INC= ifwatchd.sh + +MK= ../mk +include ${MK}/scripts.mk diff --git a/net.NetBSD/ifwatchd.sh b/net.NetBSD/ifwatchd.sh new file mode 100644 index 00000000..44c6ea31 --- /dev/null +++ b/net.NetBSD/ifwatchd.sh @@ -0,0 +1,60 @@ +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +_config_vars="$_config_vars plug_timeout" + +ifwatchd_depend() +{ + program start /usr/sbin/ifwatchd + after macnet rename wireless + before interface + provide plug +} + +ifwatchd_pre_start() +{ + # We don't start ifwatchd if we're being called from the background + yesno ${IN_BACKGROUND} && return 0 + + _exists || return 0 + + # We need a valid MAC address + # It's a basic test to ensure it's not a virtual interface + if ! _get_mac_address >/dev/null 2>&1; then + vewarn "ifwatchd only works on interfaces with a valid MAC address" + return 0 + fi + + ebegin "Starting ifwatchd on ${IFACE}" + + # Mark the us as inactive so ifwatchd can restart us + mark_service_inactive + + # Start ifwatchd + export IN_BACKGROUND=yes + start-stop-daemon --start --exec /usr/sbin/ifwatchd \ + -- -c "${RC_LIBDIR}/sh/ifwatchd-carrier.sh" \ + -n "${RC_LIBDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}" + unset IN_BACKGROUND + eend "$?" || return 1 + + einfo "Backgrounding ..." + exit 1 +} + +ifwatchd_stop() +{ + yesno ${IN_BACKGROUND} && return 0 + + start-stop-daemon --test --quiet --stop --exec /usr/sbin/ifwatchd \ + -- -c "${RC_LIBDIR}/sh/ifwatchd-carrier.sh" \ + -n "${RC_LIBDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}" \ + || return 0 + + ebegin "Stopping ifwatchd on" "${IFACE}" + start-stop-daemon --stop --exec /usr/sbin/ifwatchd \ + -- -c "${RC_LIBDIR}/sh/ifwatchd-carrier.sh" \ + -n "${RC_LIBDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}" \ + && return 0 + eend $? +} diff --git a/net/wpa_supplicant.sh b/net/wpa_supplicant.sh index 6c04a3a3..204557ad 100644 --- a/net/wpa_supplicant.sh +++ b/net/wpa_supplicant.sh @@ -47,12 +47,14 @@ wpa_supplicant_pre_start() { local opts= cfgfile= ctrl_dir= wireless=true local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli + local actfile=/etc/wpa_supplicant/wpa_cli.sh if [ ! -x "${wpas}" ]; then wpas=/sbin/wpa_supplicant wpac=/bin/wpa_cli fi [ "${RC_UNAME}" = "Linux" ] || unset wpac + [ -e "${actfile}" ] || unset wpac eval opts=\$wpa_supplicant_${IFVAR} case " ${opts} " in @@ -120,12 +122,10 @@ wpa_supplicant_pre_start() fi service_set_value ctrl_dir "${ctrl_dir}" - actfile="/etc/wpa_supplicant/wpa_cli.sh" if [ -n "${wpac}" ]; then opts="${opts} -W" - else - sleep 2 # FBSD 7.0 beta2 bug + elif service_started devd; then mark_service_inactive fi start-stop-daemon --start --exec "${wpas}" \ @@ -133,9 +133,14 @@ wpa_supplicant_pre_start() -- ${opts} -B -i "${IFACE}" \ -P "/var/run/wpa_supplicant-${IFACE}.pid" eend $? || return 1 + + # If we don't have a working wpa_cli and action file continue if [ -z "${wpac}" ]; then - ebegin "Backgrounding ..." - exit 1 + if service_started devd; then + ebegin "Backgrounding ..." + exit 1 + fi + return 0 fi # Starting wpa_supplication-0.4.0, we can get wpa_cli to @@ -147,8 +152,7 @@ wpa_supplicant_pre_start() ebegin "Starting wpa_cli on" "${IFACE}" start-stop-daemon --start --exec "${wpac}" \ --pidfile "/var/run/wpa_cli-${IFACE}.pid" \ - -- -a /etc/wpa_supplicant/wpa_cli.sh \ - -p "${ctrl_dir}" -i "${IFACE}" \ + -- -a "${actfile}" -p "${ctrl_dir}" -i "${IFACE}" \ -P "/var/run/wpa_cli-${IFACE}.pid" -B if eend $?; then ebegin "Backgrounding ..." diff --git a/sh.NetBSD/.gitignore b/sh.NetBSD/.gitignore new file mode 100644 index 00000000..cb05fa78 --- /dev/null +++ b/sh.NetBSD/.gitignore @@ -0,0 +1,2 @@ +ifwatchd-carrier.sh +ifwatchd-nocarrier.sh diff --git a/sh.NetBSD/Makefile b/sh.NetBSD/Makefile new file mode 100644 index 00000000..c93922bd --- /dev/null +++ b/sh.NetBSD/Makefile @@ -0,0 +1,6 @@ +DIR= ${RC_LIB}/sh +SRCS= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in +BIN= ifwatchd-carrier.sh ifwatchd-nocarrier.sh + +MK= ../mk +include ${MK}/scripts.mk diff --git a/sh.NetBSD/ifwatchd-carrier.sh.in b/sh.NetBSD/ifwatchd-carrier.sh.in new file mode 100644 index 00000000..4537b370 --- /dev/null +++ b/sh.NetBSD/ifwatchd-carrier.sh.in @@ -0,0 +1,5 @@ +#!@SHELL@ +# Wrapper for ifwatchd(8) + +export IN_BACKGROUND=yes +@PREFIX@@SYSCONFDIR@/init.d/net.$1 --quiet start diff --git a/sh.NetBSD/ifwatchd-nocarrier.sh.in b/sh.NetBSD/ifwatchd-nocarrier.sh.in new file mode 100644 index 00000000..d8168688 --- /dev/null +++ b/sh.NetBSD/ifwatchd-nocarrier.sh.in @@ -0,0 +1,5 @@ +#!@SHELL@ +# Wrapper for ifwatchd(8) + +export IN_BACKGROUND=yes +@PREFIX@@SYSCONFDIR@/init.d/net.$1 --quiet stop -- cgit v1.2.3