[Pkg-sysvinit-devel] Bug#874685: Do not run init scripts under systemd

Michael Biebl biebl at debian.org
Fri Sep 8 17:00:48 UTC 2017


Source: sysvinit
Version: 2.88dsf-59.9
Severity: normal
Tags: patch


The init scripts provided by the bootlogd and initscripts package are
specific to sysvinit/sysv-rc and should not be run when systemd is the
active init system as they can be actively harmful.
To ensure that, mask those services by creating a symlink pointing at
/dev/null which tells systemd to ignore those services.

While at it, simplify the maintainer scripts when dealing with those
init scripts.
By using a variable holding all init scripts we can easily iterate over
them and reverse the order. This is less error prone and avoids lots of
duplicated code.

Thanks for considering.

Michael

-- System Information:
Debian Release: buster/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (200, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.12.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=de_DE.utf8, LC_CTYPE=de_DE.utf8 (charmap=UTF-8), LANGUAGE=de_DE.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
-------------- next part --------------
>From caf88d63c053a815f9cad3753233c6a73af649a7 Mon Sep 17 00:00:00 2001
From: Michael Biebl <biebl at debian.org>
Date: Fri, 8 Sep 2017 18:48:53 +0200
Subject: [PATCH] Do not run init scripts under systemd

The init scripts provided by the bootlogd and initscripts package are
specific to sysvinit/sysv-rc and should not be run when systemd is the
active init system. To ensure that, mask those services by creating a
symlink pointing at /dev/null which tells systemd to ignore those
services.
While at it, simplify the maintainer scripts when dealing with those
init scripts.
---
 debian/bootlogd.postinst    | 24 ++++++-----
 debian/bootlogd.postrm      | 18 +++++++--
 debian/initscripts.postinst | 97 +++++++++------------------------------------
 debian/initscripts.postrm   | 45 ++++++++++-----------
 4 files changed, 68 insertions(+), 116 deletions(-)

diff --git a/debian/bootlogd.postinst b/debian/bootlogd.postinst
index eddd4210..50ab21ad 100644
--- a/debian/bootlogd.postinst
+++ b/debian/bootlogd.postinst
@@ -1,15 +1,21 @@
 #!/bin/sh
 set -e
 
-if [ -x /etc/init.d/bootlogd ]; then
-    update-rc.d bootlogd             defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/stop-bootlogd-single ]; then
-    update-rc.d stop-bootlogd-single defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/stop-bootlogd ]; then
-    update-rc.d stop-bootlogd        defaults >/dev/null || exit $?
-fi
+INITSCRIPTS="bootlogd stop-bootlogd-single stop-bootlogd"
+
+for F in $INITSCRIPTS; do
+	if [ -x /etc/init.d/$F ]; then
+		update-rc.d $F defaults >/dev/null || exit $?
+	fi
+done
+
+mkdir -p /etc/systemd/system
+for F in $INITSCRIPTS; do
+	SERVICE="$(basename $F .sh).service"
+	if [ -x /etc/init.d/$F ] && [ ! -e /etc/systemd/system/$SERVICE ]; then
+		ln -s /dev/null /etc/systemd/system/$SERVICE
+	fi
+done
 
 #
 # Create initial log files
diff --git a/debian/bootlogd.postrm b/debian/bootlogd.postrm
index 23d776bc..2705c154 100644
--- a/debian/bootlogd.postrm
+++ b/debian/bootlogd.postrm
@@ -1,6 +1,8 @@
 #!/bin/sh
 set -e
 
+INITSCRIPTS="bootlogd stop-bootlogd-single stop-bootlogd"
+
 case "$1" in
     purge)
 	#
@@ -10,9 +12,19 @@ case "$1" in
 
 	# Remove rc symlinks in the reverse dependency order they were
 	# inserted
-        update-rc.d stop-bootlogd        remove >/dev/null || exit $?
-        update-rc.d stop-bootlogd-single remove >/dev/null || exit $?
-        update-rc.d bootlogd             remove >/dev/null || exit $?
+	for F in $INITSCRIPTS; do
+		REVERSE="$F $REVERSE"
+	done
+	for F in $REVERSE; do
+		update-rc.d $F remove >/dev/null || exit $?
+	done
+
+	for F in $INITSCRIPTS; do
+		SERVICE="$(basename $F .sh).service"
+		if [ -L /etc/systemd/system/$SERVICE ]; then
+			rm /etc/systemd/system/$SERVICE
+		fi
+	done
         ;;
 esac
 
diff --git a/debian/initscripts.postinst b/debian/initscripts.postinst
index 259ce38c..94c3dbc5 100755
--- a/debian/initscripts.postinst
+++ b/debian/initscripts.postinst
@@ -81,86 +81,25 @@ if dpkg --compare-versions "$PREV_VER" lt-nl "2.88dsf-23" ; then
     fi
 fi
 
-#
-# Links in runlevel S
-#
-if [ -x /etc/init.d/mountkernfs.sh ]; then
-update-rc.d mountkernfs.sh         defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/hostname.sh ]; then
-update-rc.d hostname.sh            defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/mountdevsubfs.sh ]; then
-update-rc.d mountdevsubfs.sh       defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/checkroot.sh ]; then
-update-rc.d checkroot.sh           defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/checkroot-bootclean.sh ]; then
-update-rc.d checkroot-bootclean.sh defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/checkfs.sh ]; then
-update-rc.d checkfs.sh             defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/mountall.sh ]; then
-update-rc.d mountall.sh            defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/mountall-bootclean.sh ]; then
-update-rc.d mountall-bootclean.sh  defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/mountnfs.sh ]; then
-update-rc.d mountnfs.sh            defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/mountnfs-bootclean.sh ]; then
-update-rc.d mountnfs-bootclean.sh  defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/bootmisc.sh ]; then
-update-rc.d bootmisc.sh            defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/urandom ]; then
-update-rc.d urandom                defaults >/dev/null || exit $?
-fi
-
-#
-# Links in runlevels other than S
-#
-if [ -x /etc/init.d/halt ]; then
-update-rc.d halt                   defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/reboot ]; then
-update-rc.d reboot                 defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/umountroot ]; then
-update-rc.d umountroot             defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/umountfs ]; then
-update-rc.d umountfs               defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/umountnfs.sh ]; then
-update-rc.d umountnfs.sh           defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/sendsigs ]; then
-update-rc.d sendsigs               defaults >/dev/null || exit $?
-fi
+INITSCRIPTS="mountkernfs.sh hostname.sh mountdevsubfs.sh checkroot.sh \
+	checkroot-bootclean.sh checkfs.sh mountall.sh mountall-bootclean.sh \
+	mountnfs.sh mountnfs-bootclean.sh bootmisc.sh urandom halt reboot \
+	umountroot umountfs umountnfs.sh sendsigs killprocs single motd \
+	bootlogs rc.local rmnologin"
+
+for F in $INITSCRIPTS; do
+	if [ -x /etc/init.d/$F ]; then
+		update-rc.d $F defaults >/dev/null || exit $?
+	fi
+done
 
-if [ -x /etc/init.d/killprocs ]; then
-update-rc.d killprocs              defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/single ]; then
-update-rc.d single                 defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/motd ]; then
-update-rc.d motd                   defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/bootlogs ]; then
-update-rc.d bootlogs               defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/rc.local ]; then
-update-rc.d rc.local               defaults >/dev/null || exit $?
-fi
-if [ -x /etc/init.d/rmnologin ]; then
-update-rc.d rmnologin              defaults >/dev/null || exit $?
-fi
+mkdir -p /etc/systemd/system
+for F in $INITSCRIPTS; do
+	SERVICE="$(basename $F .sh).service"
+	if [ -x /etc/init.d/$F ] && [ ! -e /etc/systemd/system/$SERVICE ]; then
+		ln -s /dev/null /etc/systemd/system/$SERVICE
+	fi
+done
 
 #
 # Remove scripts that were left behind by older glibc (<< 2.3.2.ds1-12)
diff --git a/debian/initscripts.postrm b/debian/initscripts.postrm
index 5debca4c..99e62c04 100755
--- a/debian/initscripts.postrm
+++ b/debian/initscripts.postrm
@@ -4,7 +4,13 @@
 #
 
 set -e
- 
+
+INITSCRIPTS="mountkernfs.sh hostname.sh mountdevsubfs.sh checkroot.sh \
+	checkroot-bootclean.sh checkfs.sh mountall.sh mountall-bootclean.sh \
+	mountnfs.sh mountnfs-bootclean.sh bootmisc.sh urandom halt reboot \
+	umountroot umountfs umountnfs.sh sendsigs killprocs single motd \
+	bootlogs rc.local rmnologin"
+
 case "$1" in
   purge)
 	#
@@ -46,30 +52,19 @@ case "$1" in
 
 	# Remove rc symlinks in the reverse dependency order they were
 	# inserted
-	update-rc.d rmnologin              remove >/dev/null || exit $?
-	update-rc.d rc.local               remove >/dev/null || exit $?
-	update-rc.d motd                   remove >/dev/null || exit $?
-	update-rc.d bootlogs               remove >/dev/null || exit $?
-	update-rc.d single                 remove >/dev/null || exit $?
-	update-rc.d killprocs              remove >/dev/null || exit $?
-	update-rc.d sendsigs               remove >/dev/null || exit $?
-	update-rc.d umountnfs.sh           remove >/dev/null || exit $?
-	update-rc.d umountfs               remove >/dev/null || exit $?
-	update-rc.d umountroot             remove >/dev/null || exit $?
-	update-rc.d reboot                 remove >/dev/null || exit $?
-	update-rc.d halt                   remove >/dev/null || exit $?
-	update-rc.d urandom                remove >/dev/null || exit $?
-	update-rc.d bootmisc.sh            remove >/dev/null || exit $?
-	update-rc.d mountnfs-bootclean.sh  remove >/dev/null || exit $?
-	update-rc.d mountnfs.sh            remove >/dev/null || exit $?
-	update-rc.d mountall-bootclean.sh  remove >/dev/null || exit $?
-	update-rc.d mountall.sh            remove >/dev/null || exit $?
-	update-rc.d checkfs.sh             remove >/dev/null || exit $?
-	update-rc.d checkroot-bootclean.sh remove >/dev/null || exit $?
-	update-rc.d checkroot.sh           remove >/dev/null || exit $?
-	update-rc.d mountdevsubfs.sh       remove >/dev/null || exit $?
-	update-rc.d hostname.sh            remove >/dev/null || exit $?
-	update-rc.d mountkernfs.sh         remove >/dev/null || exit $?
+	for F in $INITSCRIPTS; do
+		REVERSE="$F $REVERSE"
+	done
+	for F in $REVERSE; do
+		update-rc.d $F remove >/dev/null || exit $?
+	done
+
+	for F in $INITSCRIPTS; do
+		SERVICE="$(basename $F .sh).service"
+		if [ -L /etc/systemd/system/$SERVICE ]; then
+			rm /etc/systemd/system/$SERVICE
+		fi
+	done
 
 	# Remove /dev/pts and /dev/shm ?
 	;;
-- 
2.14.1



More information about the Pkg-sysvinit-devel mailing list