summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2007-11-12 20:57:06 +0100
committerWilly Tarreau <w@1wt.eu>2007-11-12 20:57:06 +0100
commitca905ddbbc5b669e4046a385cc08a9e856fe0006 (patch)
tree58b3416e917db8bc65d37916638b3bf880439690
parent* upgraded version to 0.3.37 (diff)
downloadinit-scripts-ca905ddbbc5b669e4046a385cc08a9e856fe0006.tar.gz
* functions: small performance improvements (~5-10%)
By slightly reducing the number of fork/exec, the overall time needed to perform a status on a service dropped by 5-10%.
-rwxr-xr-xsbin/init.d/functions16
1 files changed, 8 insertions, 8 deletions
diff --git a/sbin/init.d/functions b/sbin/init.d/functions
index b7fda85..438c80e 100755
--- a/sbin/init.d/functions
+++ b/sbin/init.d/functions
@@ -23,15 +23,15 @@ if [ "$1" = "-c" ]; then shift; set -- $*; fi
# Configuration file to use. Default : /etc/config.rc
export CONFIG=${CONFIG:-/etc/config.rc}
-# Path to startup scripts. Default : /sbin/init.d
-# INIT_PATH=${INIT_PATH:-/sbin/init.d}
-INIT_PATH=${INIT_PATH:-`dirname $0`}
-
# Process name
PNAME=`basename $0`
PPATH=`dirname $0`
PFULLNAME=$0
+# Path to startup scripts. Default : /sbin/init.d
+# INIT_PATH=${INIT_PATH:-/sbin/init.d}
+INIT_PATH=${INIT_PATH:-$PPATH}
+
# Global variable for status information. Set to "1" while processing the right
# section.
RUNNING_SECTION=
@@ -100,7 +100,7 @@ function logit {
# usage: valueof CONFIGFILE PARAMETER
function valueof {
if [ -e "$1" ]; then
- REPLY=$(grep $'^[ \t]*'"$2"'[:= \t]*' $1|sed s,'^\('$'[ \t]*'"$2"$'[ \t:=]*''\)\([^#]*\).*$,\2,')
+ REPLY=$(sed -ne s,'^\('$'[ \t]*'"$2"$'[ \t:=]*''\)\([^#]*\).*$,\2,'p "$1")
else
REPLY=
fi
@@ -644,9 +644,9 @@ function build_default_func {
[ -f $file ] || return 1
# undefine all previously defined functions
for func in $DEFINED_FUNCTIONS ; do unset -f $func ; done
- DEFINED_FUNCTIONS=`awk '{gsub("#.*", "", $1); \
- if (match($1, "^[a-zA-Z0-9][a-zA-Z0-9_]*$")) \
- print $1 | "sort -u" }' $file `
+ DEFINED_FUNCTIONS=`awk '/^[ \t]*[a-zA-Z0-9][a-zA-Z0-9_]*/ \
+ {gsub("#.*", "", $1); if (!x[$1]) \
+ {print $1;x[$1]=1;}}' $file `
# get all first words and build a default function
for i in $DEFINED_FUNCTIONS ; do
if ! eval "declare -F $i > /dev/null" ; then