From 4255ba175bd7c3ccadc5bc894d00ccb844467067 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 8 Jan 2012 16:24:03 -0800 Subject: net: net.lo, lots of scripts The program function in depend blocks is now able to search paths by itself. If passed multiple arguments or multiple calls, at least one of the arguments passed must be a program or a shell builtin (eg ip built into busybox). If a qualified path is specified, only that path will be checked, otherwise it will be checked as a builtin, then $PATH will be checked for the named binary (via type). Signed-off-by: Robin H. Johnson --- init.d/net.lo.in | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'init.d/net.lo.in') diff --git a/init.d/net.lo.in b/init.d/net.lo.in index de393bd..2913561 100644 --- a/init.d/net.lo.in +++ b/init.d/net.lo.in @@ -172,7 +172,9 @@ _configure_variables() _which() { local i OIFS + # Empty [ -z "$1" ] && return + # check paths OIFS="$IFS" IFS=: for i in $PATH ; do @@ -181,6 +183,22 @@ _which() IFS=$OIFS } +# Like _which, but also consider shell builtins, and multiple alternatives +_program_available() +{ + [ -z "$1" ] && return 0 + local x= + for x; do + case "${x}" in + /*) [ -x "${x}" ] && break;; + *) type "${x}" >/dev/null 2>&1 && break;; + esac + unset x + done + [ -n "${x}" ] && echo $x && return 0 + return 1 +} + _show_address() { einfo "received address $(_get_inet_address "${IFACE}")" @@ -323,11 +341,10 @@ _load_modules() eval set -- \$module_${i}_program if [ -n "$1" ]; then - x= - for x; do - [ -x "${x}" ] && break - done - [ -x "${x}" ] || continue + if ! _program_available "$@" >/dev/null; then + vewarn "Skipping module $mod due to missing program: $@" + continue + fi fi if ${starting}; then eval set -- \$module_${i}_program_start @@ -335,15 +352,10 @@ _load_modules() eval set -- \$module_${i}_program_stop fi if [ -n "$1" ]; then - x= - for x; do - case "${x}" in - /*) [ -x "${x}" ] && break;; - *) type "${x}" >/dev/null 2>&1 && break;; - esac - unset x - done - [ -n "${x}" ] || continue + if ! _program_available "$@" >/dev/null; then + vewarn "Skipping module $mod due to missing program: $@" + continue + fi fi eval provides=\$module_${i}_provide -- cgit v1.2.3