We should check type output to ensure that we're really calling a shell function and not some badly named binary like stop from boinc, Gentoo #218063.
This commit is contained in:
parent
f0aacec02e
commit
e96347523f
@ -20,6 +20,15 @@ eoutdent()
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_function()
|
||||||
|
{
|
||||||
|
if [ -n "${BASH_VERSION}" ]; then
|
||||||
|
[ "$(type -t "$1")" = "function" ]
|
||||||
|
else
|
||||||
|
[ "$(type "$1" 2>/dev/null)" = "$1 is a shell function" ]
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
yesno()
|
yesno()
|
||||||
{
|
{
|
||||||
[ -z "$1" ] && return 1
|
[ -z "$1" ] && return 1
|
||||||
|
30
sh/net.sh.in
30
sh/net.sh.in
@ -28,7 +28,7 @@ depend()
|
|||||||
*) after net.lo net.lo0;;
|
*) after net.lo net.lo0;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if type depend_${IFVAR} >/dev/null 2>&1; then
|
if is_function depend_${IFVAR}; then
|
||||||
depend_${IFVAR}
|
depend_${IFVAR}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -344,7 +344,7 @@ _load_modules()
|
|||||||
# Wrap our provides
|
# Wrap our provides
|
||||||
local f=
|
local f=
|
||||||
for f in pre_start start post_start; do
|
for f in pre_start start post_start; do
|
||||||
eval "${provides}_${f}() { type ${mod}_${f} >/dev/null 2>&1 || return 0; ${mod}_${f} \"\$@\"; }"
|
eval "${provides}_${f}() { is_function ${mod}_${f} || return 0; ${mod}_${f} \"\$@\"; }"
|
||||||
done
|
done
|
||||||
|
|
||||||
eval module_${mod}_provides="${provides}"
|
eval module_${mod}_provides="${provides}"
|
||||||
@ -358,7 +358,7 @@ _load_modules()
|
|||||||
eval x=\$module_${mod}_provides
|
eval x=\$module_${mod}_provides
|
||||||
[ -z "${x}" ] && continue
|
[ -z "${x}" ] && continue
|
||||||
for f in pre_start start post_start; do
|
for f in pre_start start post_start; do
|
||||||
eval "${x}_${f}() { type ${mod}_${f} >/dev/null 2>&1 || return 0; ${mod}_${f} \"\$@\"; }"
|
eval "${x}_${f}() { is_function ${mod}_${f} || return 0; ${mod}_${f} \"\$@\"; }"
|
||||||
done
|
done
|
||||||
eval module_${x}_providedby="${mod}"
|
eval module_${x}_providedby="${mod}"
|
||||||
;;
|
;;
|
||||||
@ -462,7 +462,7 @@ start()
|
|||||||
# We up the iface twice if we have a preup to ensure it's up if
|
# We up the iface twice if we have a preup to ensure it's up if
|
||||||
# available in preup and afterwards incase the user inadvertently
|
# available in preup and afterwards incase the user inadvertently
|
||||||
# brings it down
|
# brings it down
|
||||||
if type preup >/dev/null 2>&1; then
|
if is_function preup; then
|
||||||
_up 2>/dev/null
|
_up 2>/dev/null
|
||||||
ebegin "Running preup"
|
ebegin "Running preup"
|
||||||
eindent
|
eindent
|
||||||
@ -473,7 +473,7 @@ start()
|
|||||||
_up 2>/dev/null
|
_up 2>/dev/null
|
||||||
|
|
||||||
for module in ${MODULES}; do
|
for module in ${MODULES}; do
|
||||||
if type "${module}_pre_start" >/dev/null 2>&1; then
|
if is_function "${module}_pre_start"; then
|
||||||
${module}_pre_start || exit $?
|
${module}_pre_start || exit $?
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -522,7 +522,7 @@ start()
|
|||||||
null) :;;
|
null) :;;
|
||||||
[0-9]*|*:*) _add_address ${config};;
|
[0-9]*|*:*) _add_address ${config};;
|
||||||
*)
|
*)
|
||||||
if type "${config}_start" >/dev/null 2>&1; then
|
if is_function "${config}_start"; then
|
||||||
"${config}"_start
|
"${config}"_start
|
||||||
else
|
else
|
||||||
eerror "nothing provides \`${config}'"
|
eerror "nothing provides \`${config}'"
|
||||||
@ -547,7 +547,7 @@ start()
|
|||||||
done
|
done
|
||||||
|
|
||||||
if ! ${oneworked}; then
|
if ! ${oneworked}; then
|
||||||
if type failup >/dev/null 2>&1; then
|
if is_function failup; then
|
||||||
ebegin "Running failup"
|
ebegin "Running failup"
|
||||||
eindent
|
eindent
|
||||||
failup
|
failup
|
||||||
@ -600,12 +600,12 @@ ${routes}"
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for module in ${MODULES}; do
|
for module in ${MODULES}; do
|
||||||
if type "${module}_post_start" >/dev/null 2>&1; then
|
if is_function "${module}_post_start"; then
|
||||||
${module}_post_start || exit $?
|
${module}_post_start || exit $?
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if type postup >/dev/null 2>&1; then
|
if is_function postup; then
|
||||||
ebegin "Running postup"
|
ebegin "Running postup"
|
||||||
eindent
|
eindent
|
||||||
postup
|
postup
|
||||||
@ -628,7 +628,7 @@ stop()
|
|||||||
_load_modules false
|
_load_modules false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if type predown >/dev/null 2>&1; then
|
if is_function predown; then
|
||||||
ebegin "Running predown"
|
ebegin "Running predown"
|
||||||
eindent
|
eindent
|
||||||
predown || return 1
|
predown || return 1
|
||||||
@ -641,24 +641,24 @@ stop()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for module in ${MODULES}; do
|
for module in ${MODULES}; do
|
||||||
if type "${module}_pre_stop" >/dev/null 2>&1; then
|
if is_function "${module}_pre_stop"; then
|
||||||
${module}_pre_stop || exit $?
|
${module}_pre_stop || exit $?
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
for module in ${MODULES}; do
|
for module in ${MODULES}; do
|
||||||
if type "${module}_stop" >/dev/null 2>&1; then
|
if is_function "${module}_stop"; then
|
||||||
${module}_stop
|
${module}_stop
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Only delete addresses for non PPP interfaces
|
# Only delete addresses for non PPP interfaces
|
||||||
if ! type is_ppp >/dev/null 2>&1 || ! is_ppp; then
|
if ! is_function is_ppp || ! is_ppp; then
|
||||||
_delete_addresses "${IFACE}"
|
_delete_addresses "${IFACE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for module in ${MODULES}; do
|
for module in ${MODULES}; do
|
||||||
if type "${module}_post_stop" >/dev/null 2>&1; then
|
if is_function "${module}_post_stop"; then
|
||||||
${module}_post_stop
|
${module}_post_stop
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -669,7 +669,7 @@ stop()
|
|||||||
|
|
||||||
type resolvconf >/dev/null 2>&1 && resolvconf -d "${IFACE}" 2>/dev/null
|
type resolvconf >/dev/null 2>&1 && resolvconf -d "${IFACE}" 2>/dev/null
|
||||||
|
|
||||||
if type postdown >/dev/null 2>&1; then
|
if is_function postdown; then
|
||||||
ebegin "Running postdown"
|
ebegin "Running postdown"
|
||||||
eindent
|
eindent
|
||||||
postdown
|
postdown
|
||||||
|
@ -94,7 +94,7 @@ unset _f
|
|||||||
|
|
||||||
# If we have a default command then supply a default start function
|
# If we have a default command then supply a default start function
|
||||||
if [ -n "${command}" ]; then
|
if [ -n "${command}" ]; then
|
||||||
if ! type start >/dev/null 2>&1; then
|
if ! is_function start; then
|
||||||
start() {
|
start() {
|
||||||
local _background=
|
local _background=
|
||||||
ebegin "Starting ${name:-${RC_SVCNAME}}"
|
ebegin "Starting ${name:-${RC_SVCNAME}}"
|
||||||
@ -126,7 +126,7 @@ fi
|
|||||||
# If we have a default command, procname or pidfile then supply a default stop
|
# If we have a default command, procname or pidfile then supply a default stop
|
||||||
# function
|
# function
|
||||||
if [ -n "${command}" -o -n "${procname}" -o -n "${pidfile}" ]; then
|
if [ -n "${command}" -o -n "${procname}" -o -n "${pidfile}" ]; then
|
||||||
if ! type stop >/dev/null 2>&1; then
|
if ! is_function stop; then
|
||||||
stop() {
|
stop() {
|
||||||
ebegin "Stopping ${name:-${RC_SVCNAME}}"
|
ebegin "Stopping ${name:-${RC_SVCNAME}}"
|
||||||
start-stop-daemon --stop \
|
start-stop-daemon --stop \
|
||||||
@ -143,7 +143,7 @@ while [ -n "$1" ]; do
|
|||||||
for _cmd in describe start stop ${extra_commands:-${opts}} \
|
for _cmd in describe start stop ${extra_commands:-${opts}} \
|
||||||
${extra_started_commands}; do
|
${extra_started_commands}; do
|
||||||
if [ "${_cmd}" = "$1" ]; then
|
if [ "${_cmd}" = "$1" ]; then
|
||||||
if type "$1" >/dev/null 2>&1; then
|
if is_function "$1"; then
|
||||||
# If we're in the background, we may wish to
|
# If we're in the background, we may wish to
|
||||||
# fake some commands. We do this so we can
|
# fake some commands. We do this so we can
|
||||||
# "start" ourselves from inactive which then
|
# "start" ourselves from inactive which then
|
||||||
@ -168,11 +168,11 @@ while [ -n "$1" ]; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
unset _cmd
|
unset _cmd
|
||||||
if type "$1"_pre >/dev/null 2>&1; then
|
if is_function "$1"_pre >/dev/null 2>&1; then
|
||||||
"$1"_pre || exit $?
|
"$1"_pre || exit $?
|
||||||
fi
|
fi
|
||||||
"$1" || exit $?
|
"$1" || exit $?
|
||||||
if type "$1"_post >/dev/null 2>&1; then
|
if is_function "$1"_post >/dev/null 2>&1; then
|
||||||
"$1"_post || exit $?
|
"$1"_post || exit $?
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
|
Loading…
Reference in New Issue
Block a user