summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-08-24 19:44:02 +0000
committerschwarze <schwarze@openbsd.org>2014-08-24 19:44:02 +0000
commitda641232259a38baf08c0c1d9c4f929e4660e23f (patch)
tree911524f7a4b96fd0daf88dbbad859bbae956b070
parentWhitelisting allowed services is safer and less confusing than (diff)
downloadwireguard-openbsd-da641232259a38baf08c0c1d9c4f929e4660e23f.tar.xz
wireguard-openbsd-da641232259a38baf08c0c1d9c4f929e4660e23f.zip
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@
-rw-r--r--usr.sbin/rcctl/rcctl.sh34
1 files 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 <ajacoutot@openbsd.org>
#
@@ -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()