common, hush [BUG]: exit not work in hush shell
PATCH 1/1 common, hush [BUG]: exit not work in hush shell
running the following script in u-boot:
setenv error 'if true; then
echo **** ERROR ****
exit;fi'
setenv foo echo "****************This should not be printed" setenv loadubi
setenv updfs 'if true; then
echo; echo ========== Updating rootfs ==========; echo;
if run loadubi; then
echo ***************loadubi
else;
run error
fifi'
echo ========== start ==========
run updfs foo
echo **** end
with:
=> source 80008000
========== start ==========
========== Updating rootfs ==========
## Error: "loadubi" not defined
**** ERROR ****
****************This should not be printed
**** end
=>
should not continue after printing "**** ERROR ****", as exit should skip the hole script. Fix this! I get with this patch:
=> source 80008000
========== start ==========
========== Updating rootfs ==========
## Error: "loadubi" not defined
**** ERROR ****
=>
--- common/cmd_source.c | 4 ++++ common/hush.c | 4 +++- common/main.c | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-)
common/cmd_source.c +4 -0
@@ -174,6 +174,10 @@ do_source (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])printf ("## Executing script at %08lx\n" , addr); rcode =source (addr, fit_uname); +if (rcode ==-2 ) { +debug ("Hit exit in script\n" ); + rcode =0 ; + }return rcode; }
common/hush.c +3 -1
@@ -3192,12 +3192,12 @@ int parse_stream_outer(struct in_str *inp, int flag) code =run_list (ctx.list_head);if (code ==-2 ) {/* exit */ b_free (&temp); - code =0 ;/* XXX hackish way to not allow exit from main loop */ if (inp->peek == file_peek) {printf ("exit not allowed from main input shell.\n" );continue ; } + flag |=FLAG_EXIT_FROM_LOOP ;break ; }if (code ==-1 )
@@ -3222,6 +3222,8 @@ int parse_stream_outer(struct in_str *inp, int flag)#ifndef __U_BOOT__return 0 ;#else +if (code ==-2 ) +return -2 ;return (code !=0 ) ?1 :0 ;#endif /* __U_BOOT__ */ }
common/main.c +6 -1
@@ -1469,6 +1469,7 @@ int run_command_list(const char *cmd, int len, int flag)int do_run (cmd_tbl_t * cmdtp,int flag,int argc,char *const argv[]) {int i; +int ret;if (argc <2 )return CMD_RET_USAGE ;
@@ -1481,7 +1482,11 @@ int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])return 1 ; } -if (run_command (arg, flag) !=0 ) + ret =run_command (arg, flag); +/* in case we hit an exit in a script */ +if (ret ==-2 ) +return -2 ; +if (ret !=0 )return 1 ; }return 0 ;
Signature · 1 line
1.7.7.6
PATCH 1/1 common, hush [BUG]: exit not work in hush shell
Dear Heiko Schocher,
Quoted 5 lines · In message <[email protected]> you wrote:
running the following script in u-boot:
setenv error 'if true; thenecho **** ERROR **** exit;fi'
I think I once tried to fix this, too.
See here:
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/94660
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/94661
Later, I rejected both these patches (and several other, unpublished versions I came up with during testing), because none of these worked for all tests really reliable.
common/cmd_source.c do_source (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 180
Quoted 5 lines
common/cmd_source.c +4
-0rcode =source (addr, fit_uname); +if (rcode ==-2 ) { +debug ("Hit exit in script\n" ); + rcode =0 ; + }
Hm... Note that "exit" can take an argment, which should be reflected in the return code - I mean, would it not be wrong to reurn 0 if the user has "exit 1" in his script?
Please make sure to test this extensively. When I was trying to fix a few similar issues with hush, I quickly gave up because I decided it would be an easier (and more promising) undertaking to update the whole hush code to a more recent version of hush.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." - Howard Aiken
PATCH 1/1 common, hush [BUG]: exit not work in hush shell
Hello Wolfgang,
Quoted 9 lines · Wolfgang Denk
Dear Heiko Schocher,
Quoted 5 lines · In message<[email protected]> you wrote:
running the following script in u-boot:
setenv error 'if true; thenecho **** ERROR **** exit;fi'
Quoted 8 lines
I think I once tried to fix this, too.
See here:
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/94660
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/94661Later, I rejected both these patches (and several other, unpublished versions I came up with during testing), because none of these worked
I can understand exactly how you feel... I had also several patches...
Quoted 1 line
for all tests really reliable.
Do you still have this test somewhere?
Quoted 9 lines
common/cmd_source.c do_source (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 180
Quoted 5 lines
rcode = source (addr, fit_uname);common/cmd_source.c +4
-0+if (rcode ==-2 ) { +debug ("Hit exit in script\n" ); + rcode =0 ; + }Hm... Note that "exit" can take an argment, which should be reflected in the return code - I mean, would it not be wrong to reurn 0 if the user has "exit 1" in his script?
Oh, Ok, this is a killing argument for this patch!
Quoted 4 lines
Please make sure to test this extensively. When I was trying to fix a few similar issues with hush, I quickly gave up because I decided it would be an easier (and more promising) undertaking to update the whole hush code to a more recent version of hush.
Hmm... Okay, so I have two options:
- fix "exit" with arguments
- update to a recent version of hush (where is the current code from?) But I have the gut feeling, that the problem is not in the original code, but in the u-boot adaptions, as the code in hush.c has a lot of "#ifndef __U_BOOT__" ...
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 1/1 common, hush [BUG]: exit not work in hush shell
Dear Heiko,
Quoted 2 lines · In message <[email protected]> you wrote:
Do you still have this test somewhere?
Not really. It was during the development of an install & upgrade script, and step by step I removed all constructs that the hush shell would stumble upon. Sorry.
Quoted 4 lines
Hmm... Okay, so I have two options:
- fix "exit" with arguments
- update to a recent version of hush (where is the current code from?)
Hush is part of Busybox, see http://www.busybox.net/source.html
Quoted 3 lines
But I have the gut feeling, that the problem is not in the original code, but in the u-boot adaptions, as the code in
hush.chas a lot of "#ifndef__U_BOOT__" ...
There are also bugs in the old original code, many of them long fixed since.
I once started looking into updating hush, and I have to admit that I don't understand the need for all of the "#ifndef __U_BOOT__" removals. When hush support was added, and additional 60 kB of code was a very heavy thing on most systems, so the primary intention then was to make the code as lightwight as possible. Today, a much larger percentage of users is both able to accept such code sizes and looking for the features offered. Many would even accept somewhat bigger code if they could get, for example, support for shell functions etc. Not to mention command substitution...
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Thought for the day: What if there were no hypothetical situations?