All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script]
@ 2008-03-21 20:24 Jan Kiszka
  2008-03-22 15:54 ` Roland Stigge
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jan Kiszka @ 2008-03-21 20:24 UTC (permalink / raw)
  To: Xenomai-core


[-- Attachment #1.1: Type: text/plain, Size: 71 bytes --]

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

Jan

[-- Attachment #1.2: Bug#471871: xenomai-runtime: bashism in /bin/sh script.eml --]
[-- Type: message/rfc822, Size: 6009 bytes --]

From: Raphael Geissert <atomo64@domain.hid>
To: maintonly@domain.hid
Subject: Bug#471871: xenomai-runtime: bashism in /bin/sh script
Date: Thu, 20 Mar 2008 13:39:38 -0600
Message-ID: <200803201339.41302.atomo64@domain.hid>

Package: xenomai-runtime
Severity: important
Version: 2.4.2-2
User: debian-release@domain.hid
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:
> 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;
> 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,
-- 
Atomo64 - Raphael

Please avoid sending me Word, PowerPoint or Excel attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 254 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script]
  2008-03-21 20:24 [Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script] Jan Kiszka
@ 2008-03-22 15:54 ` Roland Stigge
  2008-03-23 16:45   ` Gilles Chanteperdrix
  2008-03-24 13:51 ` Gilles Chanteperdrix
  2008-03-24 14:14 ` Gilles Chanteperdrix
  2 siblings, 1 reply; 5+ messages in thread
From: Roland Stigge @ 2008-03-22 15:54 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Xenomai-core

[-- Attachment #1: Type: text/plain, Size: 206 bytes --]

Jan Kiszka wrote:
> 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

[-- Attachment #2: xenomai.patch --]
[-- Type: text/x-diff, Size: 1025 bytes --]

diff -u scripts.orig/xeno-info scripts/xeno-info
--- scripts.orig/xeno-info	2007-12-09 11:46:37.000000000 +0100
+++ scripts/xeno-info	2008-03-22 16:50:19.000000000 +0100
@@ -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
diff -u scripts.orig/xeno-load.in scripts/xeno-load.in
--- scripts.orig/xeno-load.in	2007-12-09 11:46:37.000000000 +0100
+++ scripts/xeno-load.in	2008-03-22 16:50:57.000000000 +0100
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 # Xenomai application loader script.
 # (Processes the .runinfo files)
 # June 2004, <rpm@xenomai.org>
diff -u scripts.orig/xeno-test.in scripts/xeno-test.in
--- scripts.orig/xeno-test.in	2008-02-20 18:18:46.000000000 +0100
+++ scripts/xeno-test.in	2008-03-22 16:50:32.000000000 +0100
@@ -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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script]
  2008-03-22 15:54 ` Roland Stigge
@ 2008-03-23 16:45   ` Gilles Chanteperdrix
  0 siblings, 0 replies; 5+ messages in thread
From: Gilles Chanteperdrix @ 2008-03-23 16:45 UTC (permalink / raw)
  To: Roland Stigge; +Cc: Jan Kiszka, Xenomai-core

Roland Stigge wrote:
 > Jan Kiszka wrote:
 > > 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.

-- 


					    Gilles.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script]
  2008-03-21 20:24 [Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script] Jan Kiszka
  2008-03-22 15:54 ` Roland Stigge
@ 2008-03-24 13:51 ` Gilles Chanteperdrix
  2008-03-24 14:14 ` Gilles Chanteperdrix
  2 siblings, 0 replies; 5+ messages in thread
From: Gilles Chanteperdrix @ 2008-03-24 13:51 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Xenomai-core

[-- Attachment #1: message body and .signature --]
[-- Type: text/plain, Size: 145 bytes --]

Jan Kiszka wrote:
 > Maybe someone with idle cycles left could have a look at this.

Ok. Here comes an (untested) patch.

-- 


					    Gilles.

[-- Attachment #2: xeno-sh-scripts.diff --]
[-- Type: text/plain, Size: 4291 bytes --]

Index: scripts/xeno-info
===================================================================
--- scripts/xeno-info	(revision 3623)
+++ scripts/xeno-info	(working copy)
@@ -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 
Index: scripts/xeno-load.in
===================================================================
--- scripts/xeno-load.in	(revision 3623)
+++ scripts/xeno-load.in	(working copy)
@@ -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
Index: scripts/xeno-test.in
===================================================================
--- scripts/xeno-test.in	(revision 3623)
+++ scripts/xeno-test.in	(working copy)
@@ -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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script]
  2008-03-21 20:24 [Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script] Jan Kiszka
  2008-03-22 15:54 ` Roland Stigge
  2008-03-24 13:51 ` Gilles Chanteperdrix
@ 2008-03-24 14:14 ` Gilles Chanteperdrix
  2 siblings, 0 replies; 5+ messages in thread
From: Gilles Chanteperdrix @ 2008-03-24 14:14 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Xenomai-core

[-- Attachment #1: message body and .signature --]
[-- Type: text/plain, Size: 240 bytes --]

Jan Kiszka wrote:
 > 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.

-- 


					    Gilles.

[-- Attachment #2: xeno-sh-scripts.diff --]
[-- Type: text/plain, Size: 4286 bytes --]

Index: scripts/xeno-info
===================================================================
--- scripts/xeno-info	(revision 3623)
+++ scripts/xeno-info	(working copy)
@@ -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 
Index: scripts/xeno-load.in
===================================================================
--- scripts/xeno-load.in	(revision 3623)
+++ scripts/xeno-load.in	(working copy)
@@ -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
Index: scripts/xeno-test.in
===================================================================
--- scripts/xeno-test.in	(revision 3623)
+++ scripts/xeno-test.in	(working copy)
@@ -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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-03-24 14:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-21 20:24 [Xenomai-core] [Fwd: Bug#471871: xenomai-runtime: bashism in /bin/sh script] Jan Kiszka
2008-03-22 15:54 ` Roland Stigge
2008-03-23 16:45   ` Gilles Chanteperdrix
2008-03-24 13:51 ` Gilles Chanteperdrix
2008-03-24 14:14 ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.