Remove bashisms from scripts/extract-ikconfig
PATCH 1/1 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.
scripts/extract-ikconfig renamed from scripts/extract-ikconfig.orig +4 -4
@@ -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
Signature · 1 line
make bzImage, not war
scripts/extract-ikconfig function dump_config { · line 22
Quoted 12 lines · Christian Kujau
Hi,
I noticed that
scripts/extract-ikconfigis using/bin/shin its shebang but when/bin/shis not a symlink to bash, it breaks with:
[...]scripts/extract-ikconfig renamed from scripts/extract-ikconfig.orig +2
-2@@ -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?
Signature · 1 line
Julio M. Merino Vidal <[email protected]>
Quoted 6 lines · Julio M. Merino Vidal
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.
Signature · 1 line
make bzImage, not war
Quoted 9 lines · Christian Kujau
Quoted 6 lines · Julio M. Merino Vidal
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.
Signature · 1 line
Julio M. Merino Vidal <[email protected]>
Quoted 10 lines · Christian Kujau
Quoted 6 lines · Julio M. Merino Vidal
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
Quoted 2 lines · Willy Tarreau
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.
Signature · 1 line
make bzImage, not war
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).
--- scripts/extract-ikconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/extract-ikconfig +3 -3
@@ -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"