Skip to contentSkip to conversation

[Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script]

Xenomai-core Jan Kiszka 3 participants 5 messages Mar 21, 2008 – Mar 24, 2008

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

Maybe someone with idle cycles left could have a look at this.

Jan

Package: xenomai-runtime
Severity: important
Version: 2.4.2-2
User: [email protected]
Usertags: goal-dash

Hello maintainer,

While performing an archive wide checkbashisms (from the 'devscripts' package) check I've found your package containing several /bin/sh scripts making use of a bashism.

checkbashisms' output:

Quoted 12 lines

possible bashism in ./usr/bin/xeno-load line 130 (should be >word 2>&1):
$sudo kill -SIGINT $children_pids >& /dev/null
possible bashism in ./usr/bin/xeno-info line 77 (brace expansion):
ls -l /usr/lib/lib{g,stdc}++.so 2>/dev/null | awk -F. \
possible bashism in ./usr/bin/xeno-test line 63 (local foo=bar):
local neededApplets="awk basename cut date dd dirname egrep grep head
possible bashism in ./usr/bin/xeno-test line 65 (local foo=bar):
local foundAll=1
possible bashism in ./usr/bin/xeno-test line 81 (local foo=bar):
local foundAll=1
possible bashism in ./usr/bin/xeno-test line 114 (local foo=bar):

    local jobsct=$1;
Quoted 8 lines

possible bashism in ./usr/bin/xeno-test line 123 (cnt=$((cnt + 1)) does not work in dash): jobsct=$((jobsct-1));
possible bashism in ./usr/bin/xeno-test line 162 (local foo=bar):
local filter=" grep -E '$whatconf'"
possible bashism in ./usr/bin/xeno-test line 277 (local foo=bar):
local file=$1
possible bashism in ./usr/bin/xeno-test line 382 (should be 'b = a'):

    if test "$res" == "0" ; then

Not using bash as /bin/sh is likely to lead to errors or unexpected behaviours.
Please be aware that although
bash is currently the default /bin/sh there's a release goal for Lenny to make dash the default /bin/sh[1].

If you want more information about dash as /bin/sh, you can read:
http://lists.debian.org/debian-release/2008/01/msg00189.html
https://wiki.ubuntu.com/DashAsBinSh

For more information please refer to the Debian Policy section 10.4 supporting this argument at:
http://www.debian.org/doc/debian-policy/ch-files.html#s-scripts

HINT: sometimes these bugs are already fixed in Ubuntu, look at the PTS

[1]http://release.debian.org/lenny/goals.txt

Thank you,

Signature · 4 lines
Atomo64 - Raphael

Please avoid sending me Word, PowerPoint or Excel attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
#1 lore raw
Quoted 1 line · Jan Kiszka

Maybe someone with idle cycles left could have a look at this.

Idle? Preempted, at most!

Attached is what I will apply to the Debian version. Feel free to do as well...

bye,
Roland

xeno-info +1 -1
diff -u scripts.orig/xeno-info scripts/xeno-info
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #
 # This file has been lifted 'as is' from linux/scripts/ver_linux.
 # Adapted to be run also under the BusyBox. If you want to test it under the BusyBox use
xeno-load.in +1 -1
diff -u scripts.orig/xeno-load.in scripts/xeno-load.in
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 # Xenomai application loader script.
 # (Processes the .runinfo files)
 # June 2004, <[email protected]>
xeno-test.in +1 -1
diff -u scripts.orig/xeno-test.in scripts/xeno-test.in
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 
 # Adapted to be run also under the BusyBox. 
 # If you want to test it this way, do: sh xeno-test
#2 lore raw
Quoted 7 lines · Roland Stigge
Quoted 1 line · Jan Kiszka

Maybe someone with idle cycles left could have a look at this.

Idle? Preempted, at most!

Attached is what I will apply to the Debian version. Feel free to do as well...

IMO, making the scripts sh compliant is worth the trouble: we do not know what shell the users will use, this would give us maximum compatibility.

Signature · 1 line
					    Gilles.
#3 lore raw
In reply to Jan Kiszka
Quoted 1 line · Jan Kiszka

Maybe someone with idle cycles left could have a look at this.

Ok. Here comes an (untested) patch.

Signature · 1 line
					    Gilles.
xeno-info +1 -1
Index: scripts/xeno-info
===================================================================
@@ -74,7 +74,7 @@ ldd -v > /dev/null 2>&1 && ldd -v || ldd
 'NR==1{print "Dynamic linker (ldd)  ", $NF}'
 fi
 
-ls -l /usr/lib/lib{g,stdc}++.so  2>/dev/null | awk -F. \
+ls -l /usr/lib/libg++.so /usr/lib/libstdc++.so  2>/dev/null | awk -F. \
        '{print "Linux C++ Library      " $4"."$5"."$6}'
 
 if test 0 -eq $withBusybox ; then 
xeno-load.in +1 -1
Index: scripts/xeno-load.in
===================================================================
@@ -127,7 +127,7 @@ children_pids=""
 cleanup () {
 
     if test \! "x$children_pids" = x; then
-       $sudo kill -SIGINT $children_pids >& /dev/null
+       $sudo kill -SIGINT $children_pids > /dev/null 2>&1
        children_pids=""
        sleep 1
     fi
xeno-test.in +23 -10
Index: scripts/xeno-test.in
===================================================================
@@ -60,9 +60,9 @@ pidFile=/var/lock/`basename $0.$$`.pids
 
 checkUtilities() {
   # Check for needed helper utilities
-  local neededApplets="awk basename cut date dd dirname egrep grep head
+  neededApplets="awk basename cut date dd dirname egrep grep head
 		       kill md5sum mount sleep test top uname zcat"
-  local foundAll=1
+  foundAll=1
   for  _j in $neededApplets
   do
     if test -z "`which $_j`"; then
@@ -74,11 +74,17 @@ checkUtilities() {
     echo "Please build busybox's ash with support for getopts"
     foundAll=0
   fi
-  if test $foundAll -eq 0 ; then exit 3 ; fi
+  if test $foundAll -eq 0 ; then 
+      needApplets=""
+      foundAll=""
+      exit 3
+  fi
+  needApplets=""
+  foundAll=""
 }
 
 checkHelpers() {
-  local foundAll=1
+  foundAll=1
   if test -z "`which script`" -a -n "$logging"; then
       echo "You will not be able to log (-L option) as script is missing"
       foundAll=0
@@ -91,7 +97,11 @@ checkHelpers() {
       echo "You will not be able to upload (-U option) as curl is missing"
       foundAll=0
   fi
-  if test $foundAll -eq 0 ; then exit 3 ; fi
+  if test $foundAll -eq 0 ; then 
+      foundAll=""
+      exit 3
+  fi
+  foundAll=""
 }
 
 loudly() {
@@ -111,7 +121,7 @@ dd_jobs=
 mkload() { dd if=$device of=/dev/null $* & }
 
 generate_loads() {
-    local jobsct=$1;
+    jobsct=$1;
     # if test -z "$1"; then echo Skipping generate_loads; return; fi
     shift 1
     if test 0 -eq $withBusybox ; then
@@ -120,13 +130,14 @@ generate_loads() {
 	trap cleanup_load EXIT	# under all exit conditions
     fi
     while test $jobsct -ge 1; do 
-        jobsct=$((jobsct-1)); 
+        jobsct=`expr $jobsct - 1`; 
         mkload
         dd_jobs="$dd_jobs $!" ;
     done
 
     echo dd workload started, pids $dd_jobs stored in $pidFile
     echo  $dd_jobs > $pidFile
+    jobsct=""
 }
 
 cleanup_load() {
@@ -159,7 +170,7 @@ boxinfo() { # static info, show once
     loudly md5sum /proc/cpuinfo	'# cpuinfo fingerprint'
 
     # how much of the config do we want ?
-    local filter=" grep -E '$whatconf'"
+    filter=" grep -E '$whatconf'"
     [ "$verbose" = 1 ] && filter=
     if test -f /proc/config.gz; then # get the config
          loudly zcat /proc/config.gz | $filter
@@ -170,6 +181,7 @@ boxinfo() { # static info, show once
 
     [ -d /proc/adeos ] && for f in /proc/adeos/*; do loudly cat $f; done
     [ -d /proc/ipipe ] && for f in /proc/ipipe/*; do loudly cat $f; done
+    filter=""
 }
 
 boxstatus() {     # get dynamic status
@@ -274,7 +286,7 @@ verbose=
 dateargs='+%y%m%d.%H%M%S'
 
 sendit() {
-    local file=$1
+    file=$1
     if test "$sendit" = 'm' ; then
 	echo "mailing $file to $email"
 	if test -n "$file" ; then
@@ -290,6 +302,7 @@ sendit() {
     else
 	echo "sendit unsupported option '$sendit'"
     fi
+    file=""
 }
 
 handle_options() {	# called for XENOTEST_OPTS, ARGV
@@ -379,7 +392,7 @@ if test "$logging" != "" ; then
     # restart inside a script invocation, passing appropriate args
     script -c "`dirname $0`/xeno-test $loadpass $latpass $*" $wfile
     res="$?"
-    if test "$res" == "0" ; then
+    if test "$res" = "0" ; then
 	sendit $wfile
     fi
 else
#4 lore raw
In reply to Jan Kiszka
Quoted 1 line · Jan Kiszka

Maybe someone with idle cycles left could have a look at this.

We do not need expr actually, $(()) also works with sh, but can not make reference to a variable without a $, hence the new patch.

Signature · 1 line
					    Gilles.
xeno-info +1 -1
Index: scripts/xeno-info
===================================================================
@@ -74,7 +74,7 @@ ldd -v > /dev/null 2>&1 && ldd -v || ldd
 'NR==1{print "Dynamic linker (ldd)  ", $NF}'
 fi
 
-ls -l /usr/lib/lib{g,stdc}++.so  2>/dev/null | awk -F. \
+ls -l /usr/lib/libg++.so /usr/lib/libstdc++.so  2>/dev/null | awk -F. \
        '{print "Linux C++ Library      " $4"."$5"."$6}'
 
 if test 0 -eq $withBusybox ; then 
xeno-load.in +1 -1
Index: scripts/xeno-load.in
===================================================================
@@ -127,7 +127,7 @@ children_pids=""
 cleanup () {
 
     if test \! "x$children_pids" = x; then
-       $sudo kill -SIGINT $children_pids >& /dev/null
+       $sudo kill -SIGINT $children_pids > /dev/null 2>&1
        children_pids=""
        sleep 1
     fi
xeno-test.in +23 -10
Index: scripts/xeno-test.in
===================================================================
@@ -60,9 +60,9 @@ pidFile=/var/lock/`basename $0.$$`.pids
 
 checkUtilities() {
   # Check for needed helper utilities
-  local neededApplets="awk basename cut date dd dirname egrep grep head
+  neededApplets="awk basename cut date dd dirname egrep grep head
 		       kill md5sum mount sleep test top uname zcat"
-  local foundAll=1
+  foundAll=1
   for  _j in $neededApplets
   do
     if test -z "`which $_j`"; then
@@ -74,11 +74,17 @@ checkUtilities() {
     echo "Please build busybox's ash with support for getopts"
     foundAll=0
   fi
-  if test $foundAll -eq 0 ; then exit 3 ; fi
+  if test $foundAll -eq 0 ; then 
+      needApplets=""
+      foundAll=""
+      exit 3
+  fi
+  needApplets=""
+  foundAll=""
 }
 
 checkHelpers() {
-  local foundAll=1
+  foundAll=1
   if test -z "`which script`" -a -n "$logging"; then
       echo "You will not be able to log (-L option) as script is missing"
       foundAll=0
@@ -91,7 +97,11 @@ checkHelpers() {
       echo "You will not be able to upload (-U option) as curl is missing"
       foundAll=0
   fi
-  if test $foundAll -eq 0 ; then exit 3 ; fi
+  if test $foundAll -eq 0 ; then 
+      foundAll=""
+      exit 3
+  fi
+  foundAll=""
 }
 
 loudly() {
@@ -111,7 +121,7 @@ dd_jobs=
 mkload() { dd if=$device of=/dev/null $* & }
 
 generate_loads() {
-    local jobsct=$1;
+    jobsct=$1;
     # if test -z "$1"; then echo Skipping generate_loads; return; fi
     shift 1
     if test 0 -eq $withBusybox ; then
@@ -120,13 +130,14 @@ generate_loads() {
 	trap cleanup_load EXIT	# under all exit conditions
     fi
     while test $jobsct -ge 1; do 
-        jobsct=$((jobsct-1)); 
+        jobsct=$(($jobsct-1));
         mkload
         dd_jobs="$dd_jobs $!" ;
     done
 
     echo dd workload started, pids $dd_jobs stored in $pidFile
     echo  $dd_jobs > $pidFile
+    jobsct=""
 }
 
 cleanup_load() {
@@ -159,7 +170,7 @@ boxinfo() { # static info, show once
     loudly md5sum /proc/cpuinfo	'# cpuinfo fingerprint'
 
     # how much of the config do we want ?
-    local filter=" grep -E '$whatconf'"
+    filter=" grep -E '$whatconf'"
     [ "$verbose" = 1 ] && filter=
     if test -f /proc/config.gz; then # get the config
          loudly zcat /proc/config.gz | $filter
@@ -170,6 +181,7 @@ boxinfo() { # static info, show once
 
     [ -d /proc/adeos ] && for f in /proc/adeos/*; do loudly cat $f; done
     [ -d /proc/ipipe ] && for f in /proc/ipipe/*; do loudly cat $f; done
+    filter=""
 }
 
 boxstatus() {     # get dynamic status
@@ -274,7 +286,7 @@ verbose=
 dateargs='+%y%m%d.%H%M%S'
 
 sendit() {
-    local file=$1
+    file=$1
     if test "$sendit" = 'm' ; then
 	echo "mailing $file to $email"
 	if test -n "$file" ; then
@@ -290,6 +302,7 @@ sendit() {
     else
 	echo "sendit unsupported option '$sendit'"
     fi
+    file=""
 }
 
 handle_options() {	# called for XENOTEST_OPTS, ARGV
@@ -379,7 +392,7 @@ if test "$logging" != "" ; then
     # restart inside a script invocation, passing appropriate args
     script -c "`dirname $0`/xeno-test $loadpass $latpass $*" $wfile
     res="$?"
-    if test "$res" == "0" ; then
+    if test "$res" = "0" ; then
 	sendit $wfile
     fi
 else