From da641232259a38baf08c0c1d9c4f929e4660e23f Mon Sep 17 00:00:00 2001 From: schwarze Date: Sun, 24 Aug 2014 19:44:02 +0000 Subject: [PATCH] Delete the function svc_get_all(). In svc_is_avail(), this simplifies the code by getting rid of the loop. When running "rcctl status", this allows to not run svc_is_special() - which spawns a grep - for each and every service, resulting in a 20% speedup. As a bonus, we get the special services listed at the end, where they are easier to see than mixed in with the daemons. ok ajacoutot@ jasper@ --- usr.sbin/rcctl/rcctl.sh | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/usr.sbin/rcctl/rcctl.sh b/usr.sbin/rcctl/rcctl.sh index c4f049f88e4..a4b991a0652 100644 --- a/usr.sbin/rcctl/rcctl.sh +++ b/usr.sbin/rcctl/rcctl.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: rcctl.sh,v 1.19 2014/08/24 19:00:46 schwarze Exp $ +# $OpenBSD: rcctl.sh,v 1.20 2014/08/24 19:44:02 schwarze Exp $ # # Copyright (c) 2014 Antoine Jacoutot # @@ -69,18 +69,6 @@ svc_default_enabled() return ${_ret} } -svc_get_all() -{ - local _i - - ( - ls -A /etc/rc.d | grep -v rc.subr - for _i in ${_special_services}; do - echo ${_i} - done - ) | sort -} - svc_get_flags() { local daemon_flags @@ -112,23 +100,23 @@ svc_get_status() svc_get_flags ${_svc} | sed '/^$/d' svc_is_enabled ${_svc} else - for _i in $(svc_get_all); do - svc_is_special ${_i} && unset _affix || _affix="_flags" - echo "${_i}${_affix}=$(svc_get_flags ${_i})" + for _i in $(ls -A /etc/rc.d | grep -v rc.subr); do + echo "${_i}_flags=$(svc_get_flags ${_i})" + done + for _i in ${_special_services}; do + echo "${_i}=$(svc_get_flags ${_i})" done fi } svc_is_avail() { - local _i + local _svc=$1 + [ -n "${_svc}" ] || return 1 - for _i in $(svc_get_all); do - if [ ${_i} = "$1" ]; then - return 0 - fi - done - return 1 + [ "${_svc}" == "rc.subr" ] && return 1 + [ -x "/etc/rc.d/${_svc}" ] && return 0 + svc_is_special ${_svc} } svc_is_base() -- 2.20.1