summaryrefslogtreecommitdiffstats
path: root/usr.sbin/rcctl
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-08-27 23:50:45 +0000
committerschwarze <schwarze@openbsd.org>2014-08-27 23:50:45 +0000
commit50fbd3a176513d21f9386dd5481563134f87144f (patch)
tree2ef2cc8a7098da11871b71d6459cbe9e6b92ca6f /usr.sbin/rcctl
parentRemove $_ usage that warns under Perl 5.18. (diff)
downloadwireguard-openbsd-50fbd3a176513d21f9386dd5481563134f87144f.tar.xz
wireguard-openbsd-50fbd3a176513d21f9386dd5481563134f87144f.zip
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@.
Diffstat (limited to 'usr.sbin/rcctl')
-rw-r--r--usr.sbin/rcctl/rcctl.sh22
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