[PATCH 9/9] init-d-script: /bin/sh as interpreter and small optimizations
Trek
trek00 at inbox.ru
Fri Aug 28 07:22:08 BST 2020
Suggest /bin/sh as interpreter, in order not to break scripts
executed before the $remote_fs facility, that is before /usr
is mounted, on systems without initrd.
Parameter expansions are used instead of executing
/usr/bin/basename. The is_call_implemented function is
optimized so as not to scan the filesystem.
On synthetic tests (starting /bin/true as daemon), it is near
20% faster when running with FANCYTTY=0 (fancy output is much
slower so the gains are lower in percentage).
---
debian/init-d-script | 8 ++++----
debian/init-d-script.5 | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/debian/init-d-script b/debian/init-d-script
index 48a0cb6e..eebc9522 100755
--- a/debian/init-d-script
+++ b/debian/init-d-script
@@ -18,7 +18,7 @@ PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH
is_call_implemented() {
- command -V $1 > /dev/null 2>&1
+ PATH= command -V $1 >/dev/null 2>&1
}
do_usage() {
@@ -180,15 +180,15 @@ unset DAEMON DAEMON_ARGS DESC NAME COMMAND_NAME PIDFILE \
RELOAD_ARGS RELOAD_SIGNAL START_ARGS STOP_ARGS
SCRIPTNAME="$__init_d_script_name"
-scriptbasename="$(basename "$__init_d_script_name")"
+scriptbasename=${__init_d_script_name##*/}
if [ "$scriptbasename" != "init-d-script" ] ; then
. "$__init_d_script_name"
else
exit 0
fi
-NAME=${NAME:=$(basename $DAEMON)}
-DESC=${DESC:=$NAME}
+: ${NAME:=${DAEMON##*/}}
+: ${DESC:=$NAME}
: ${COMMAND_NAME:=${NAME}}
# Do not use pid file if $PIDFILE is 'none'. Otherwise, generate from
diff --git a/debian/init-d-script.5 b/debian/init-d-script.5
index 50d6bb97..cf1c769c 100644
--- a/debian/init-d-script.5
+++ b/debian/init-d-script.5
@@ -14,7 +14,7 @@ precedence.
This is a simple example on how init\-d\-script can be used to start
and stop a daemon with PID file support:
.Bd -literal -offset indent
-#!/usr/bin/env /lib/init/init\-d\-script
+#!/bin/sh /lib/init/init\-d\-script
### BEGIN INIT INFO
# Provides: atd
# Required\-Start: $syslog $time $remote_fs
--
2.20.1
More information about the Debian-init-diversity
mailing list