Skip to contentSkip to conversation

tools: kernel-chktaint: Fix bashism, simplify code

PATCH In review Petr Vorel 3 participants 4 messages Jun 18, 2024 – Jun 22, 2024 Kselftest

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/2 tools: kernel-chktaint: Fix bashism, simplify code

'==' is bashism, '=' needs to be used for comparison. With this fix script can work on systems where the default shell is dash, busybox ash or any other strictly POSIX compatible shell.

While at it, also improve:
* remove "x" in the comparison (not needed for decades)
* use $# for checking number of arguments
* cleanup whitespace

Fixes 4ab5a5d2a4a22 ("tools: add a kernel-chktaint to tools/debugging")
---
 tools/debugging/kernel-chktaint | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/debugging/kernel-chktaint +3 -3
index 279be06332be9..adbb1d621ccd4 100755
@@ -18,11 +18,11 @@ retrieved from /proc/sys/kernel/tainted on another system.
 EOF
 }
 
-if [ "$1"x != "x" ]; then
-	if  [ "$1"x == "--helpx" ] || [ "$1"x == "-hx" ] ; then
+if [ $# -gt 0 ]; then
+	if  [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
 		usage
 		exit 1
-	elif  [ $1 -ge 0 ] 2>/dev/null ; then
+	elif  [ $1 -ge 0 ] 2>/dev/null; then
 		taint=$1
 	else
 		echo "Error: Parameter '$1' not a positive integer. Aborting." >&2
Signature · 1 line
2.45.1
author
#1 lore raw

PATCH 2/2 tools: build: Fix bashisms in run.sh

Fix bashisms:

* exit -1 converted to 255 (exit|return with negative status code is not supported on some shells)
* 'function' is useless

This fixes problems on dash, busybox ash or any other strictly POSIX compatible shell.

Fixes c819e2cf2eb6f ("tools build: Add new build support")
---
 tools/build/tests/run.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
tools/build/tests/run.sh +8 -8
index 2c54e4d435464..87d6cad57b20c 100755
@@ -1,20 +1,20 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 
-function test_ex {
+test_ex() {
 	make -C ex V=1 clean > ex.out 2>&1
 	make -C ex V=1 >> ex.out 2>&1
 
 	if [ ! -x ./ex/ex ]; then
 	  echo FAILED
-	  exit -1
+	  exit 255
 	fi
 
 	make -C ex V=1 clean > /dev/null 2>&1
 	rm -f ex.out
 }
 
-function test_ex_suffix {
+test_ex_suffix() {
 	make -C ex V=1 clean > ex.out 2>&1
 
 	# use -rR to disable make's builtin rules
@@ -24,19 +24,19 @@ function test_ex_suffix {
 
 	if [ -x ./ex/ex ]; then
 	  echo FAILED
-	  exit -1
+	  exit 255
 	fi
 
 	if [ ! -f ./ex/ex.o -o ! -f ./ex/ex.i -o ! -f ./ex/ex.s ]; then
 	  echo FAILED
-	  exit -1
+	  exit 255
 	fi
 
 	make -C ex V=1 clean > /dev/null 2>&1
 	rm -f ex.out
 }
 
-function test_ex_include {
+test_ex_include() {
 	make -C ex V=1 clean > ex.out 2>&1
 
 	# build with krava.h include
@@ -45,7 +45,7 @@ function test_ex_include {
 
 	if [ ! -x ./ex/ex ]; then
 	  echo FAILED
-	  exit -1
+	  exit 255
 	fi
 
 	# build without the include
@@ -54,7 +54,7 @@ function test_ex_include {
 
 	if [ ! -x ./ex/ex ]; then
 	  echo FAILED
-	  exit -1
+	  exit 255
 	fi
 
 	make -C ex V=1 clean > /dev/null 2>&1
Signature · 1 line
2.45.1
Acked-by on v1 1/2
#2 lore raw
In reply to Petr Vorel
Quoted 11 lines · Petr Vorel

'==' is bashism, '=' needs to be used for comparison. With this fix script can work on systems where the default shell is dash, busybox ash or any other strictly POSIX compatible shell.

While at it, also improve:
* remove "x" in the comparison (not needed for decades)
* use $# for checking number of arguments
* cleanup whitespace

Fixes 4ab5a5d2a4a22 ("tools: add a kernel-chktaint to tools/debugging")

Ciao, Thorsten

Acked-by on v1 1/2
#3 lore raw
In reply to Petr Vorel
Quoted 11 lines · Petr Vorel

'==' is bashism, '=' needs to be used for comparison. With this fix script can work on systems where the default shell is dash, busybox ash or any other strictly POSIX compatible shell.

While at it, also improve:
* remove "x" in the comparison (not needed for decades)
* use $# for checking number of arguments
* cleanup whitespace

Fixes 4ab5a5d2a4a22 ("tools: add a kernel-chktaint to tools/debugging")

Thanks.

Quoted 23 lines
---
 tools/debugging/kernel-chktaint | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/debugging/kernel-chktaint +3 -3
index 279be06332be9..adbb1d621ccd4 100755
@@ -18,11 +18,11 @@ retrieved from /proc/sys/kernel/tainted on another system.
 EOF
 }
 
-if [ "$1"x != "x" ]; then
-	if  [ "$1"x == "--helpx" ] || [ "$1"x == "-hx" ] ; then
+if [ $# -gt 0 ]; then
+	if  [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
 		usage
 		exit 1
-	elif  [ $1 -ge 0 ] 2>/dev/null ; then
+	elif  [ $1 -ge 0 ] 2>/dev/null; then
 		taint=$1
 	else
 		echo "Error: Parameter '$1' not a positive integer. Aborting." >&2
Signature · 1 line
~Randy