diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2015-04-29 11:05:17 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2015-04-29 11:05:17 +0000 |
commit | 011355d3170ae0da36e79dd171aff3d7beac2c1a (patch) | |
tree | 5964cae69711d9a99db722d58e001a9eebbe0ec6 | |
parent | b1becf51bfc6361de70f503a24b5d15a2162f203 (diff) |
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@
-rw-r--r-- | etc/rc.d/rc.subr | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr index 2f0f113e50a..95ec7787084 100644 --- a/etc/rc.d/rc.subr +++ b/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 <ajacoutot@openbsd.org> # Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -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 |