Sometimes when I restart a service after changing its configuration file
I accidentally type:

 # rcctl restart smtpd.conf
 /usr/sbin/rcctl: ${cached_svc_is_special_smtpd.conf}: bad substitution
 /usr/sbin/rcctl[556]: set: cached_svc_is_special_smtpd.conf: is not an
 identifier
 rcctl: service smtpd.conf does not exist

The message about a bad substitution is not helpful to the user, who
only needs to know that smtpd.conf is not a service.

The problem is the period in "smtpd.conf". Line 189 of rcctl fails:
  _cached=$(eval print \${cached_svc_is_special_${_svc}})

Special service names are thus limited to underscores and alphanumerics
because they're concatenated into shell variable names. So instead of
checking for [ -n ${_svc} ] at the top of svc_is_special, we ought to
check that ${_svc} contains only legal characters.

I check only in svc_is_special and not in any of the other places that
test [ -n ${_svc} ] my only goal is to fix the error message people get
when they try to start or enable configuration files, and this is the
only place that needs the error. Adding a similar check to svc_is_avail
would block an error message when someone creates an executable file
called /etc/rc.d/foo.bar and then calls "rcctl enable foo.bar", but in
that case I think the message "${foo.bar_flags}: bad substitution" is
more helpful---the user is trying to create a service with an illegal
name and the system is telling him why it will never work.

Regards,
Anthony
 
Index: usr.sbin/rcctl/rcctl.sh
===================================================================
RCS file: /open/anoncvs/cvs/src/usr.sbin/rcctl/rcctl.sh,v
retrieving revision 1.104
diff -u -p -u -r1.104 rcctl.sh
--- usr.sbin/rcctl/rcctl.sh     30 Jul 2016 06:25:21 -0000      1.104
+++ usr.sbin/rcctl/rcctl.sh     6 Sep 2016 15:07:47 -0000
@@ -182,7 +182,7 @@ svc_is_meta()
 svc_is_special()
 {
        local _svc=$1
-       [ -n "${_svc}" ] || return
+       [ "${_svc}" = +([_0-9A-Za-z])} ] || return
 
        local _cached _ret
 

Reply via email to