Bug#928249: sysv-rc: fix styling

Dmitry Bogatov KAction at debian.org
Tue Apr 30 16:03:22 BST 2019


Source: sysvinit
Version: 2.94-2
Severity: wishlist

I hope to make running shellcheck part of `make test', and here is
little step in that direction. This patch fixes only suggestions, that
require no refactoring -- just more of double quotes.

Review is welcome.

 From fe660a07d02f5ad46ec39924a5ab4354682a8fd0 Mon Sep 17 00:00:00 2001
From: Dmitry Bogatov <KAction at debian.org>
Date: Mon, 29 Apr 2019 03:13:41 +0000
Subject: [PATCH] Fix style in /etc/init.d/rc script

Fix several style recommentations in /etc/init.d/rc script, suggested
by shellcheck(1).
---
 debian/src/sysv-rc/rc | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/debian/src/sysv-rc/rc b/debian/src/sysv-rc/rc
index ed828cf5..025a1c54 100755
--- a/debian/src/sysv-rc/rc
+++ b/debian/src/sysv-rc/rc
@@ -38,7 +38,9 @@ stty onlcr 0>&1

 # Now find out what the current and what the previous runlevel are.

+# shellcheck disable=SC2153 # this variable is set by /sbin/init
 runlevel=$RUNLEVEL
+
 # Get first argument. Set new runlevel to this argument.
 [ "$1" != "" ] && runlevel=$1
 if [ "$runlevel" = "" ]
@@ -117,16 +119,15 @@ case "$CONCURRENCY" in
 		startup() {
 			action=$1
 			shift
-			scripts="$@"
-			for script in $scripts ; do
-				$debug "$script" $action
+			for script ; do
+				"$script" "$action"
 			done
 		}
 		;;
 esac

 # Is there an rc directory for this new runlevel?
-if [ -d /etc/rc$runlevel.d ]
+if [ -d "/etc/rc$runlevel.d" ]
 then
 	case "$runlevel" in
 		0|6)
@@ -150,7 +151,7 @@ then
 	elif [ "$previous" != N ]
 	then
 		CURLEVEL=""
-		for s in /etc/rc$runlevel.d/K*
+		for s in "/etc/rc$runlevel.d/K"*
 		do
 			# Extract order value from symlink
 			level=${s#/etc/rc$runlevel.d/K}
@@ -161,10 +162,10 @@ then
 			fi
 			CURLEVEL=$level
 			SCRIPTS=""
-			for i in /etc/rc$runlevel.d/K$level*
+			for i in "/etc/rc$runlevel.d/K$level"*
 			do
 				# Check if the script is there.
-				[ ! -f $i ] && continue
+				[ ! -f "$i" ] && continue

 				#
 				# Find stop script in previous runlevel but
@@ -198,7 +199,7 @@ then
 	else
 		# Now run the START scripts for this runlevel.
 		CURLEVEL=""
-		for s in /etc/rc$runlevel.d/S*
+		for s in "/etc/rc$runlevel.d/S"*
 		do
 			# Extract order value from symlink
 			level=${s#/etc/rc$runlevel.d/S}
@@ -209,9 +210,9 @@ then
 			fi
 			CURLEVEL=$level
 			SCRIPTS=""
-			for i in /etc/rc$runlevel.d/S$level*
+			for i in "/etc/rc$runlevel.d/S$level"*
 			do
-				[ ! -f $i ] && continue
+				[ ! -f "$i" ] && continue

 				suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9]}
 				if [ "$previous" != N ]
@@ -252,4 +253,3 @@ fi
 trap - EXIT # Disable emergency handler

 exit 0
-
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://www.chiark.greenend.org.uk/pipermail/debian-init-diversity/attachments/20190430/ae32c43b/attachment.sig>


More information about the Debian-init-diversity mailing list