diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-08-27 23:50:46 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-08-27 23:50:46 +0000 |
commit | 6bc19bc2cb948e05e9d5c33125230722cb0a9f60 (patch) | |
tree | 1ecbb770ef1b0545675caa523b23d55b973df6d1 | |
parent | 53030bb9f9eb02d91aa30fb3783bd810dc720cbd (diff) |
Disentangle svc_default_enabled_flags() and svc_get_flags().
This saves three expensive function calls in svc_default_enabled_flags(),
two to _rc_parse_conf() and one to svc_get_flags(). No functional change.
Feedback and ok ajacoutot@.
-rw-r--r-- | usr.sbin/rcctl/rcctl.sh | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/usr.sbin/rcctl/rcctl.sh b/usr.sbin/rcctl/rcctl.sh index f4ab15ea30c..8966c9b95f5 100644 --- a/usr.sbin/rcctl/rcctl.sh +++ b/usr.sbin/rcctl/rcctl.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: rcctl.sh,v 1.28 2014/08/26 22:39:09 schwarze Exp $ +# $OpenBSD: rcctl.sh,v 1.29 2014/08/27 23:50:45 schwarze Exp $ # # Copyright (c) 2014 Antoine Jacoutot <ajacoutot@openbsd.org> # @@ -70,16 +70,18 @@ svc_default_enabled() return ${_ret} } +# For security reasons, only call this if the service is enabled. +# To avoid namespace pollution, only call it in a subshell. svc_default_enabled_flags() { local _svc=$1 [ -n "${_svc}" ] || return + svc_is_special ${_svc} && return - _rc_parse_conf /etc/rc.conf - pkg_scripts=${_svc} - unset ${_svc}_flags - echo $(svc_get_flags ${_svc}) - _rc_parse_conf + FUNCS_ONLY=1 + rc_cmd() { } + . /etc/rc.d/${_svc} >/dev/null 2>&1 + [ -n "${daemon_flags}" ] && echo ${daemon_flags} } svc_get_flags() @@ -99,14 +101,8 @@ svc_get_flags() fi [ -z "${daemon_flags}" ] && \ daemon_flags="$(eval echo \${${_svc}_flags})" - # rc.d shell script: no other way to get "${daemon_flags}" [ -z "${daemon_flags}" ] && \ - daemon_flags=$( - FUNCS_ONLY=1 - rc_cmd() { } - . /etc/rc.d/${_svc} >/dev/null 2>&1 - echo ${daemon_flags} - ) + deamon_flags="$(svc_default_enabled_flags ${_svc})" echo ${daemon_flags} | sed '/^$/d' fi |