package/tpm2-abrmd: rewrite init script

This brings the init script in line with current standards, including
PID file management.

The chown & chmod commands in the check_device function will run only
for systems without udev, and the permissions have been adjusted to
those udev would set.

Signed-off-by: Fiona Klute (WIWA) <fiona.klute@gmx.de>
Signed-off-by: Julien Olivain <ju.o@free.fr>
This commit is contained in:
Fiona Klute (WIWA)
2025-07-07 16:10:52 +02:00
committed by Julien Olivain
parent e0dcb7ba02
commit de9d24bf2c
2 changed files with 45 additions and 51 deletions

View File

@@ -1138,7 +1138,6 @@ package/tinycbor/0001-Makefile-add-DISABLE_WERROR.patch lib_patch.Upstream
package/tinycompress/0001-wave-add-time.h-missing-header-inclusion.patch lib_patch.Upstream
package/tinydtls/0001-sha2-sha2.c-fix-build-on-big-endian.patch lib_patch.Upstream
package/tinyxml/0001-In-stamp-always-advance-the-pointer-if-p-0xef.patch lib_patch.Upstream
package/tpm2-abrmd/S80tpm2-abrmd Shellcheck lib_sysv.Indent lib_sysv.Variables
package/tpm2-tss/0001-Temporary-fix-for-build-without-C.patch lib_patch.Upstream
package/transmission/S92transmission Shellcheck lib_sysv.ConsecutiveEmptyLines lib_sysv.Indent lib_sysv.Variables
package/triggerhappy/S10triggerhappy Shellcheck lib_sysv.Indent lib_sysv.Variables

View File

@@ -1,74 +1,69 @@
#!/bin/sh
my_name="$0"
DAEMON="tpm2-abrmd"
PIDFILE="/var/run/$DAEMON.pid"
check_required_files() {
[ -f "$1" ] || {
echo "$my_name: $1 is missing"
exit 1
}
}
TABRMD_ARGS="--tcti=device --logger=syslog --max-connections=20"
# shellcheck source=/dev/null
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
check_device() {
ls -1 /dev/tpm[0-9]* > /dev/null 2>&1 || {
echo "device driver not loaded, skipping."
if ! ls /dev/tpm[0-9]* > /dev/null 2>&1; then
echo "no TPM device found, skipping."
exit 0
}
chown tss:tss /dev/tpm[0-9]* && chmod 600 /dev/tpm*
}
rm_stale_pidfile() {
if [ -e "$1" ]; then
exe="/proc/$(cat "$1")/exe"
{ [ -s "$exe" ] && [ "$(readlink -f "$exe")" = "$2" ]; } || rm -f "$1"
fi
if [ ! -x /sbin/udevd ]; then
chown tss:tss /dev/tpm[0-9]* && chmod 660 /dev/tpm*
fi
}
start() {
printf "Starting tpm2-abrmd: "
printf 'Starting %s: ' "$DAEMON"
check_device
rm_stale_pidfile /var/run/tpm2-abrmd.pid /usr/sbin/tpm2-abrmd
start-stop-daemon -S -q -o -b -m -p /var/run/tpm2-abrmd.pid -c tss:tss -x /usr/sbin/tpm2-abrmd -- ${DAEMON_OPTS} || {
# shellcheck disable=SC2086 # we need the word splitting
start-stop-daemon --start --background --chuid tss:tss --make-pidfile \
--pidfile "$PIDFILE" --exec "/usr/sbin/$DAEMON" \
-- ${TABRMD_ARGS}
status=$?
if [ "$status" -eq 0 ]; then
echo "OK"
else
echo "FAIL"
exit 1
}
pidof /usr/sbin/tpm2-abrmd > /var/run/tpm2-abrmd.pid
echo "OK"
fi
return "$status"
}
stop() {
printf "Stopping tpm2-abrmd: "
start-stop-daemon -K -q -o -p /var/run/tpm2-abrmd.pid -u tss -x /usr/sbin/tpm2-abrmd || {
printf 'Stopping %s: ' "$DAEMON"
start-stop-daemon --stop --pidfile "$PIDFILE" --exec "/usr/sbin/$DAEMON"
status=$?
if [ "$status" -eq 0 ]; then
echo "OK"
else
echo "FAIL"
exit 1
}
rm_stale_pidfile /var/run/tpm2-abrmd.pid /usr/sbin/tpm2-abrmd
echo "OK"
return "$status"
fi
while start-stop-daemon --stop --test --quiet --pidfile "$PIDFILE" \
--exec "/usr/sbin/$DAEMON"; do
sleep 0.1
done
rm -f "$PIDFILE"
return "$status"
}
check_required_files /etc/dbus-1/system.d/tpm2-abrmd.conf
# defaults
DAEMON_OPTS="--tcti=device --logger=syslog --max-connections=20"
# Read configuration variable file if it is present
[ -r /etc/default/tpm2-abrmd ] && . /etc/default/tpm2-abrmd
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
sleep 1
start
;;
start|stop|restart)
"$1";;
reload)
# Restart, since there is no true "reload" feature.
restart;;
*)
echo "Usage: tpm2-abrmd {start|stop|restart|reload}" >&2
exit 1
esac
exit 0