From 7a4b86c7fdcf3f2fd95b4522224665d14d78f169 Mon Sep 17 00:00:00 2001 From: ajacoutot <> Date: Wed, 29 Apr 2015 11:05:16 +0000 Subject: [PATCH] Check arguments before eval so we don't end up with a cryptic error message. reported by jasper@ While here: _rc_is_supported() -> _rc_not_supported() - saves a fork - reduces triple negation to double negation in _rc_not_supported() - simplifie condition for rc_restart=NO from schwarze@ ok jasper@ schwarze@ --- src/etc/rc.d/rc.subr | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/etc/rc.d/rc.subr b/src/etc/rc.d/rc.subr index 2f0f113e..95ec7787 100644 --- a/src/etc/rc.d/rc.subr +++ b/src/etc/rc.d/rc.subr @@ -1,4 +1,4 @@ -# $OpenBSD: rc.subr,v 1.93 2015/03/28 07:34:16 ajacoutot Exp $ +# $OpenBSD: rc.subr,v 1.94 2015/04/29 11:05:16 ajacoutot Exp $ # # Copyright (c) 2010, 2011, 2014 Antoine Jacoutot # Copyright (c) 2010, 2011 Ingo Schwarze @@ -16,21 +16,29 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +_rc_actions="start stop restart reload check" +readonly _rc_actions + _rc_err() { [ -n "${1}" ] && echo "${1}" 1>&2 [ -n "${2}" ] && exit "${2}" || exit 1 } -_rc_is_supported() { - local _enotsup - eval _enotsup=\${rc_$1} - [ X"${_enotsup}" != X"NO" ] +_rc_not_supported() { + local _a _enotsup + for _a in ${_rc_actions}; do + if [ "${1}" == "${_a}" ]; then + eval _enotsup=\${rc_$1} + break + fi + done + [ X"${_enotsup}" == X"NO" ] } _rc_usage() { local _a _allsup - for _a in start stop restart reload check; do - _rc_is_supported ${_a} && _allsup="${_allsup:+$_allsup|}${_a}" + for _a in ${_rc_actions}; do + _rc_not_supported ${_a} || _allsup="${_allsup:+$_allsup|}${_a}" done _rc_err "usage: $0 [-df] ${_allsup}" } @@ -168,11 +176,11 @@ rc_cmd() { [ X"${rc_usercheck}" != X"NO" -a X"$1" = "Xcheck" ] || \ _rc_err "$0: need root privileges" - if ! (_rc_is_supported start && _rc_is_supported stop); then + if _rc_not_supported start || _rc_not_supported stop; then rc_restart=NO fi - if ! _rc_is_supported $1; then + if _rc_not_supported $1; then [ -n "${INRC}" ] && exit 1 _rc_err "$0: $1 is not supported" fi