Antoine,
I've been following this thread and noted that you did add _rc_check_name
to rc.subr and call it in rcctl. This looks clean and comprehensive. Two
thoughts, however:
1. I had to look at the pattern match in _rc_check_name for a while
before I understood it; the suggestion below makes it clearer for
someone like myself
2. The second suggestion handles the edge case where the argument to rcctl
matches the name of a subdirectory of rc.d. Note that ls_rcscripts()
earlier in the script has the same test
John
Index: etc/rc.d/rc.subr
===================================================================
RCS file: /cvs/src/etc/rc.d/rc.subr,v
retrieving revision 1.116
diff -u -p -r1.116 rc.subr
--- etc/rc.d/rc.subr 7 Sep 2016 13:12:42 -0000 1.116
+++ etc/rc.d/rc.subr 15 Sep 2016 15:58:29 -0000
@@ -61,7 +61,7 @@ _rc_rm_runfile() {
}
_rc_check_name() {
- [[ $1 == +([_[:alpha:]])+(|[_[:alnum:]]) ]]
+ [[ $1 == +([_[:alpha:]])*([_[:alnum:]]) ]]
}
_rc_do() {
Index: usr.sbin/rcctl/rcctl.sh
===================================================================
RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
retrieving revision 1.105
diff -u -p -r1.105 rcctl.sh
--- usr.sbin/rcctl/rcctl.sh 7 Sep 2016 13:13:13 -0000 1.105
+++ usr.sbin/rcctl/rcctl.sh 15 Sep 2016 15:58:29 -0000
@@ -141,8 +141,8 @@ svc_is_avail()
local _svc=$1
_rc_check_name "${_svc}" || return
- [ -x "/etc/rc.d/${_svc}" ] && return
- svc_is_special ${_svc}
+ [[ -x "/etc/rc.d/${_svc}" && ! -d "/etc/rc.d/${_svc}" ]] \
+ || svc_is_special ${_svc}
}
svc_is_base()
Sent: Tuesday, September 06, 2016 at 2:13 PM
From: "Antoine Jacoutot" <
ajac...@bsdfrog.org>
To: "Anthony Coulter" <
b...@anthonycoulter.name>
Cc:
te...@openbsd.org
Subject: Re: Improve error message in rcctl(8)