summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2016-06-19 10:50:28 +0000
committerAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2016-06-19 10:50:28 +0000
commit174908888547e97b4000f6093b0e619456debf41 (patch)
tree408b0172d3d13b763888ceecf2cc603a94fb0d85
parent2938941271f93d76d13909c897b976289e553de6 (diff)
Cache result of often used functions (svc_is_{base,meta,special}).
Large speedup when iterating over all rc.d scripts. with and ok robert@
-rw-r--r--usr.sbin/rcctl/rcctl.sh20
1 files changed, 19 insertions, 1 deletions
diff --git a/usr.sbin/rcctl/rcctl.sh b/usr.sbin/rcctl/rcctl.sh
index 2b92f4e847e..4011ab45307 100644
--- a/usr.sbin/rcctl/rcctl.sh
+++ b/usr.sbin/rcctl/rcctl.sh
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $OpenBSD: rcctl.sh,v 1.97 2016/06/19 10:46:08 ajacoutot Exp $
+# $OpenBSD: rcctl.sh,v 1.98 2016/06/19 10:50:27 ajacoutot Exp $
#
# Copyright (c) 2014, 2015 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -150,7 +150,13 @@ svc_is_base()
local _svc=$1
[ -n "${_svc}" ] || return
+ [ "${_cached_svc_is_base[${_svc}]}" ] && \
+ return ${_cached_svc_is_base[${_svc}]}
+
grep -qw "^${_svc}_flags" /etc/rc.conf
+
+ _cached_svc_is_base[${_svc}]=$?
+ return ${_cached_svc_is_base[${_svc}]}
}
svc_is_meta()
@@ -158,7 +164,13 @@ svc_is_meta()
local _svc=$1
[ -n "${_svc}" ] || return
+ [ "${_cached_svc_is_meta[${_svc}]}" ] && \
+ return ${_cached_svc_is_meta[${_svc}]}
+
[ -r "/etc/rc.d/${_svc}" ] && ! grep -qw "^rc_cmd" /etc/rc.d/${_svc}
+
+ _cached_svc_is_meta[${_svc}]=$?
+ return ${_cached_svc_is_meta[${_svc}]}
}
svc_is_special()
@@ -166,7 +178,13 @@ svc_is_special()
local _svc=$1
[ -n "${_svc}" ] || return
+ [ "${_cached_svc_is_special[${_svc}]}" ] && \
+ return ${_cached_svc_is_special[${_svc}]}
+
echo ${_special_svcs} | grep -qw -- ${_svc}
+
+ _cached_svc_is_special[${_svc}]=$?
+ return ${_cached_svc_is_special[${_svc}]}
}
svc_ls()