[PATCH 5/5] Optimize killproc using parameter expansions

Trek trek00 at inbox.ru
Tue Apr 26 22:48:23 BST 2022


The signal parsing code of the killproc function was using sed
to remove the -SIG prefix of the signal, but with parameter
expansions it is near 8x faster.

Thanks: Carl Albing <carl-albing at bethel.edu>
http://www.chiark.greenend.org.uk/pipermail/debian-init-diversity/2020-August/003437.html
---
 init-functions | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/init-functions b/init-functions
index 1760a3b..e25c32a 100644
--- a/init-functions
+++ b/init-functions
@@ -144,8 +144,7 @@ killproc () {
         name_param="--name $base --pidfile $pidfile"
     fi
 
-    sig=$(echo ${2:-} | sed -e 's/^-\(.*\)/\1/')
-    sig=$(echo $sig | sed -e 's/^SIG\(.*\)/\1/')
+    sig=${2:-} sig=${sig#-} sig=${sig#SIG}
     if [ "$sig" = 15 ] || [ "$sig" = TERM ]; then
         is_term_sig="terminate_signal"
     fi
-- 
2.20.1



More information about the Debian-init-diversity mailing list