2007-06-09 19:22:18

by Christian Kujau

[permalink] [raw]
Subject: [PATCH] Remove bashisms from scripts/extract-ikconfig

Hi,

I noticed that scripts/extract-ikconfig is using /bin/sh in its shebang
but when /bin/sh is not a symlink to bash, it breaks with:

# scripts/extract-ikconfig /boot/vmlinux
scripts/extract-ikconfig: 11: function: not found
scripts/extract-ikconfig: 12: typeset: not found

The diff below seems to fix this.

Signed-off-by: Christian Kujau <[email protected]>

--- linux-2.6-dev/scripts/extract-ikconfig.orig 2007-06-01 22:53:49.000000000 +0200
+++ linux-2.6-dev/scripts/extract-ikconfig 2007-06-01 23:00:54.000000000 +0200
@@ -8,8 +8,8 @@ test -e $binoffset || cc -o $binoffset .

IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54"
IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44"
-function dump_config {
- typeset file="$1"
+dump_config() {
+ file="$1"

start=`$binoffset $file $IKCFG_ST 2>/dev/null`
[ "$?" != "0" ] && start="-1"
@@ -18,8 +18,8 @@ function dump_config {
fi
end=`$binoffset $file $IKCFG_ED 2>/dev/null`

- let start="$start + 8"
- let size="$end - $start"
+ start="`expr $start + 8`"
+ size="`expr $end - $start`"

dd if="$file" ibs=1 skip="$start" count="$size" 2>/dev/null | zcat


--
make bzImage, not war


2007-06-09 19:27:16

by Julio M. Merino Vidal

[permalink] [raw]
Subject: Re: [PATCH] Remove bashisms from scripts/extract-ikconfig


On 09/06/2007, at 21:22, Christian Kujau wrote:

> Hi,
>
> I noticed that scripts/extract-ikconfig is using /bin/sh in its
> shebang but when /bin/sh is not a symlink to bash, it breaks with:
> [...]
> @@ -18,8 +18,8 @@ function dump_config {
> fi
> end=`$binoffset $file $IKCFG_ED 2>/dev/null`
>
> - let start="$start + 8"
> - let size="$end - $start"
> + start="`expr $start + 8`"
> + size="`expr $end - $start`"

Wouldn't this be better expressed as:

start=$(($start + 8))
size=$(($end - $start))

to avoid invoking a subshell?

--
Julio M. Merino Vidal <[email protected]>


2007-06-09 19:34:48

by Christian Kujau

[permalink] [raw]
Subject: Re: [PATCH] Remove bashisms from scripts/extract-ikconfig

On Sat, 9 Jun 2007, Julio M. Merino Vidal wrote:
> Wouldn't this be better expressed as:
>
> start=$(($start + 8))
> size=$(($end - $start))
>
> to avoid invoking a subshell?

This is certainly possible for lots for scripts, but was not the "scope"
of this patch. ` is not bash-specific and does not break anything.

--
make bzImage, not war

2007-06-09 19:39:32

by Julio M. Merino Vidal

[permalink] [raw]
Subject: Re: [PATCH] Remove bashisms from scripts/extract-ikconfig

On 09/06/2007, at 21:34, Christian Kujau wrote:

> On Sat, 9 Jun 2007, Julio M. Merino Vidal wrote:
>> Wouldn't this be better expressed as:
>>
>> start=$(($start + 8))
>> size=$(($end - $start))
>>
>> to avoid invoking a subshell?
>
> This is certainly possible for lots for scripts, but was not the
> "scope" of this patch. ` is not bash-specific and does not break
> anything.

$((...)) is not bash-specific either.

--
Julio M. Merino Vidal <[email protected]>


2007-06-09 19:53:48

by Willy Tarreau

[permalink] [raw]
Subject: Re: [PATCH] Remove bashisms from scripts/extract-ikconfig

On Sat, Jun 09, 2007 at 09:34:36PM +0200, Christian Kujau wrote:
> On Sat, 9 Jun 2007, Julio M. Merino Vidal wrote:
> >Wouldn't this be better expressed as:
> >
> > start=$(($start + 8))
> > size=$(($end - $start))
> >
> >to avoid invoking a subshell?
>
> This is certainly possible for lots for scripts, but was not the "scope"
> of this patch. ` is not bash-specific and does not break anything.

That's wrong. It will now require "expr" to be present and working on
the machine, eventhough it's certainly needed for other parts of the
kernel. Also, the remaining function will be considerably slower than
what it initially was. If it's called very frequently, it can be a
problem.

I agree with Julio that if you want to fix the code for its bashism,
you should not change its behaviour and stay as much as possible close
to what it initially did.

Also, beware that the "typeset file=y" did another thing : declare "file"
as local to the function. With your change, any global variable called
"file" will have its content wiped after a call to this function. You
should ensure that it is not used anywhere else, or better, change its
name for something less common than "file".

Regards,
Willy

2007-06-09 20:14:34

by Christian Kujau

[permalink] [raw]
Subject: Re: [PATCH] Remove bashisms from scripts/extract-ikconfig

On Sat, 9 Jun 2007, Willy Tarreau wrote:
> That's wrong. It will now require "expr" to be present and working on
> the machine, eventhough it's certainly needed for other parts of the

Oh, I was under the strange assumption that "expr" was a shell-builtin.
Well, it's not so I guess I'll just live with the bashism or try to
implement your proposals.

Thank you both for your comments,
Christian.
--
make bzImage, not war

2007-11-14 23:45:38

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] Remove bashisms from scripts/extract-ikconfig

Hi Christian,

Does the patch below satisfy your needs here?

Thanks,
~Randy

---

From: Christian Kujau <[email protected]>

Remove bashisms from scripts/extract-ikconfig (function and
typeset words).

Tested under dash v0.5.4 (latest/current).

Signed-off-by: Christian Kujau <[email protected]>
Signed-off-by: Randy Dunlap <[email protected]>
---
scripts/extract-ikconfig | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

--- linux-2.6.24-rc2-git2.orig/scripts/extract-ikconfig
+++ linux-2.6.24-rc2-git2/scripts/extract-ikconfig
@@ -8,8 +8,9 @@ test -e $binoffset || cc -o $binoffset .

IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54"
IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44"
-function dump_config {
- typeset file="$1"
+
+dump_config() {
+ file="$1"

start=`$binoffset $file $IKCFG_ST 2>/dev/null`
[ "$?" != "0" ] && start="-1"
@@ -27,7 +28,6 @@ function dump_config {
exit 0
}

-
usage()
{
echo " usage: extract-ikconfig [b]zImage_filename"