Package: systemd
Version: 208-1
Severity: normal
File: /lib/lsb/init-functions.d/40-systemd
/lib/lsb/init-functions.d/40-systemd unconditionally uses "set +e; set
+u". This can change the behavior of init scripts that use "set -e"
and/or "set -u".
The systemd integration should not rely on "set +e" or "set +u", but
instead work correctly in all cases:
Instead of "set +u", access variables in a way that doesn't trigger an
exception when the variable is not set: "${foo:-}" will result in an
empty string when foo is not set.
Instead of "set +e", explicitly catch commands that might fail, for example
something-that-might-fail || :
It is still okay to use "set +e; set +u" in the redirection code when
control is not returned to the init script.
I've attached an *untested* patch implementing what I described
above. Not sure if I missed anything.
Ansgar
diff --git a/debian/init-functions.d/40-systemd b/debian/init-functions.d/40-systemd
index a213afc..809ec7a 100644
--- a/debian/init-functions.d/40-systemd
+++ b/debian/init-functions.d/40-systemd
@@ -1,21 +1,18 @@
# -*-Shell-script-*-
# /lib/lsb/init-functions
+_use_systemctl=0
if [ -d /run/systemd/system ]; then
- # Some init scripts use "set -e" and "set -u", we don't want that
- # here
- set +e
- set +u
- if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ]; then
+ if [ -n "${DPKG_MAINTSCRIPT_PACKAGE:-}" ]; then
# If we are called by a maintainer script, chances are good that a
# new or updated sysv init script was installed. Reload daemon to
# pick up any changes.
- systemctl daemon-reload
+ systemctl daemon-reload || :
fi
# Redirect SysV init scripts when executed by the user
- if [ $PPID -ne 1 ] && [ -z "$init" ] && [ -z "$_SYSTEMCTL_SKIP_REDIRECT" ]; then
+ if [ $PPID -ne 1 ] && [ -z "${init:-}" ] && [ -z "${_SYSTEMCTL_SKIP_REDIRECT:-}" ]; then
case $(readlink -f "$0") in
/etc/init.d/*)
_use_systemctl=1
@@ -23,7 +20,7 @@ if [ -d /run/systemd/system ]; then
# but can through the init script.
prog=${0##*/}
service="${prog%.sh}.service"
- if [ "$(systemctl -p CanReload show $service 2>/dev/null)" = "CanReload=no" ] && [ "$1" = "reload" ]; then
+ if [ "$(systemctl -p CanReload show $service 2>/dev/null)" = "CanReload=no" ] && [ "${1:-}" = "reload" ]; then
_use_systemctl=0
fi
;;
@@ -31,8 +28,6 @@ if [ -d /run/systemd/system ]; then
else
export _SYSTEMCTL_SKIP_REDIRECT="true"
fi
-else
- _use_systemctl=0
fi
systemctl_redirect () {
@@ -73,6 +68,11 @@ systemctl_redirect () {
}
if [ "$_use_systemctl" = "1" ]; then
+ # Some init scripts use "set -e" and "set -u", we don't want that
+ # here
+ set +e
+ set +u
+
if [ "x$1" = xstart -o \
"x$1" = xstop -o \
"x$1" = xrestart -o \