Control: reassign -1 systemd
Control: tags -1 + patch

Hello!

Please see the attached patch which should avoid the case
where *only* reload is possible (and which will apparently
screw with your system in some cases) when the user directly
invokes the sysvinit script.

(What the patch does is basically 1. move prog= and service= earlier
since we're going to use it earlier. 2. move LoadState=masked check
earlier and change it to use exit 0 instead of return 0 since it's
no longer used in a function.)

Regards,
Andreas Henriksson
>From 439eafea92448094f8f62db2a7ce81c6136058c3 Mon Sep 17 00:00:00 2001
From: Andreas Henriksson <andr...@fatal.se>
Date: Wed, 25 Nov 2015 12:22:11 +0100
Subject: [PATCH] /lib/lsb/init-functions.d/40-systemd: don't reload masked
 services

When a service is masked the native service does not support
reload, so the lsb hooks would then allow fallback on init script
reload function.

Move the check for masked services earlier and bail out with exit 0
so that does not happen.

(Still a bit confusing that there's no output at all to inform
the user calling the init script for a masked service about this,
but I've been told it's on purpose eg. to avoid spamming the logs.)

Closes: #804882
---
 debian/extra/init-functions.d/40-systemd | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/debian/extra/init-functions.d/40-systemd b/debian/extra/init-functions.d/40-systemd
index 53f5058..003d3ba 100644
--- a/debian/extra/init-functions.d/40-systemd
+++ b/debian/extra/init-functions.d/40-systemd
@@ -11,6 +11,15 @@ if [ -d /run/systemd/system ]; then
         systemctl daemon-reload || true
     fi
 
+    prog=${0##*/}
+    service="${prog%.sh}.service"
+
+    # Don't try to run masked services. Don't check for errors, if
+    # this errors, we'll just call systemctl and possibly explode
+    # there.
+    state=$(systemctl -p LoadState show $service 2>/dev/null)
+    [ "$state" = "LoadState=masked" ] && exit 0
+
     # Redirect SysV init scripts when executed by the user
     if [ $PPID -ne 1 ] && [ -z "${init:-}" ] && [ -z "${_SYSTEMCTL_SKIP_REDIRECT:-}" ]; then
         case $(readlink -f "$0") in
@@ -18,8 +27,6 @@ if [ -d /run/systemd/system ]; then
                 _use_systemctl=1
                 # Some services can't reload through the .service file,
                 # 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
                     _use_systemctl=0
                 fi
@@ -53,12 +60,6 @@ systemctl_redirect () {
 
     service="${prog%.sh}.service"
 
-    # Don't try to run masked services. Don't check for errors, if
-    # this errors, we'll just call systemctl and possibly explode
-    # there.
-    state=$(systemctl -p LoadState show $service 2>/dev/null)
-    [ "$state" = "LoadState=masked" ] && return 0
-
     # avoid deadlocks during bootup and shutdown from units/hooks
     # which call "invoke-rc.d service reload" and similar, since
     # the synchronous wait plus systemd's normal behaviour of
-- 
2.1.4

Reply via email to