diff options
author | Robert Peichaer <rpe@cvs.openbsd.org> | 2014-08-20 17:15:18 +0000 |
---|---|---|
committer | Robert Peichaer <rpe@cvs.openbsd.org> | 2014-08-20 17:15:18 +0000 |
commit | 04c6e2b89e3a87c8c740bd0c2435e2b4fe4886bb (patch) | |
tree | f0d7a1da71c69457184853893b55ffdf86187377 /usr.sbin/rcctl | |
parent | a47309dbc09be0a8c46e86fa4379522baa84a96b (diff) |
Store the positional args in vars with meaningful names which makes the arg
checking block easier to comprehend.
OK ajacoutot@
Diffstat (limited to 'usr.sbin/rcctl')
-rwxr-xr-x | usr.sbin/rcctl/rcctl.sh | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/usr.sbin/rcctl/rcctl.sh b/usr.sbin/rcctl/rcctl.sh index 7cdb316bb32..a2ed6004ad6 100755 --- a/usr.sbin/rcctl/rcctl.sh +++ b/usr.sbin/rcctl/rcctl.sh @@ -275,49 +275,54 @@ rm_flags() rcconf_edit_end } +action=$1 +svc=$2 +flag=$3 +flags=$* + if [ $# -gt 0 ]; then - if [ -n "$2" ]; then - if ! svc_is_avail $2; then - _rc_err "service $2 does not exist" + if [ -n "$svc" ]; then + if ! svc_is_avail $svc; then + _rc_err "service $svc does not exist" fi - elif [ "$1" != "status" ]; then + elif [ "$action" != "status" ]; then usage fi - if [ -n "$3" ]; then - if [ "$3" = "flags" ]; then - if [ "$1" != "enable" ]; then + if [ -n "$flag" ]; then + if [ "$flag" = "flags" ]; then + if [ "$action" != "enable" ]; then _rc_err "\"flags\" can only be set with \"enable\"" fi - if svc_is_special $2; then - _rc_err "\"$2\" is a special variable, cannot set \"flags\"" + if svc_is_special $svc; then + _rc_err "\"$svc\" is a special variable, cannot set \"flags\"" fi else usage fi fi - case $1 in + case $action in disable) - needs_root $1 - if ! svc_is_base $2 && ! svc_is_special $2; then - rm_from_pkg_scripts $2 + needs_root $svc + if ! svc_is_base $svc && ! svc_is_special $svc; then + rm_from_pkg_scripts $svc fi - rm_flags $2 + rm_flags $svc ;; enable) - needs_root $1 - add_flags $* - if ! svc_is_base $2 && ! svc_is_special $2; then - append_to_pkg_scripts $2 + needs_root $action + add_flags $flags + if ! svc_is_base $svc && ! svc_is_special $svc; then + append_to_pkg_scripts $svc fi ;; status) - svc_get_status $2 + svc_get_status $svc ;; start|stop|restart|reload|check) - if svc_is_special $2; then - _rc_err "\"$2\" is a special variable, no rc.d(8) script" + if svc_is_special $svc; then + _rc_err "\"$svc\" is a special variable, no rc.d(8) script" fi - /etc/rc.d/$2 $1 + /etc/rc.d/$svc $action ;; *) usage |