summaryrefslogtreecommitdiff
path: root/etc/rc.d/rc.subr
diff options
context:
space:
mode:
authorVadim Zhukov <zhuk@cvs.openbsd.org>2013-04-04 06:50:45 +0000
committerVadim Zhukov <zhuk@cvs.openbsd.org>2013-04-04 06:50:45 +0000
commit9c50f2e1f39c014891728c961ea54c6039fef679 (patch)
treee433d5a92f27743cb70f3c4b3fbb3c8ae9b30444 /etc/rc.d/rc.subr
parent6c8bcbe5139c7a32e19f73a0dfb9f0ed534523e1 (diff)
Show only available actions in RC script usage messages.
Also, prettify representation of actions list a bit. a lot of input and ok halex@ aja@ also ok schwarze@ small nit spotted by marc@ "makes a lot of sense to me" todd@
Diffstat (limited to 'etc/rc.d/rc.subr')
-rw-r--r--etc/rc.d/rc.subr23
1 files changed, 18 insertions, 5 deletions
diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr
index e61ca53e0f8..040a0e93eb2 100644
--- a/etc/rc.d/rc.subr
+++ b/etc/rc.d/rc.subr
@@ -1,4 +1,4 @@
-# $OpenBSD: rc.subr,v 1.68 2012/11/19 07:10:59 ajacoutot Exp $
+# $OpenBSD: rc.subr,v 1.69 2013/04/04 06:50:44 zhuk Exp $
#
# Copyright (c) 2010, 2011 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -24,8 +24,18 @@ rc_err() {
exit 1
}
+rc_is_supported() {
+ local _enotsup
+ eval _enotsup=\${rc_$1}
+ [ X"${_enotsup}" != X"NO" ]
+}
+
rc_usage() {
- rc_err "usage: $0 [-df] {start|check|reload|restart|stop}"
+ local _a _allsup
+ for _a in start stop restart reload check; do
+ rc_is_supported ${_a} && _allsup="${_allsup:+$_allsup|}${_a}"
+ done
+ rc_err "usage: $0 [-df] (${_allsup})"
}
rc_write_runfile() {
@@ -95,14 +105,17 @@ rc_wait() {
}
rc_cmd() {
- local _bg _enotsup _n
+ local _bg _n
[ "$(id -u)" -eq 0 ] || \
[ X"${rc_usercheck}" != X"NO" -a X"$1" = "Xcheck" ] || \
rc_err "$0: need root privileges"
- eval _enotsup=\${rc_${1}}
- if [ X"${_enotsup}" = X"NO" ]; then
+ if ! (rc_is_supported start && rc_is_supported stop); then
+ rc_restart=NO
+ fi
+
+ if ! rc_is_supported $1; then
[ -n "${INRC}" ] && exit 1
rc_err "$0: $1 is not supported"
fi