From 7bebe9579ee5ea1cfcfcdf25032dbab80ccc489f Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 29 Nov 2010 14:19:59 +0000 Subject: [cmdline] Match user expectations for &&, ||, goto, and exit The && and || operators should be left-associative, since that is how they are treated in most other languages (including C and Unix shell). For example, in the command: dhcp net0 && goto dhcp_ok || echo No DHCP on net0 if the "dhcp net0" fails then the "echo" should be executed. After an "exit" or a successful "goto", further commands on the same line should never be executed. For example: goto somewhere && echo This should never be printed exit 0 && echo This should never be printed exit 1 && echo This should never be printed An "exit" should cause the current shell or script to terminate and return the specified exit status to its caller. For example: chain test.ipxe && echo Success || echo Failure [in test.ipxe] #!ipxe exit 0 should echo "Success". Signed-off-by: Michael Brown --- src/image/script.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/image') diff --git a/src/image/script.c b/src/image/script.c index f9d5a39..1c3ff82 100644 --- a/src/image/script.c +++ b/src/image/script.c @@ -34,6 +34,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include #include +#include struct image_type script_image_type __image_type ( PROBE_NORMAL ); @@ -106,13 +107,8 @@ static int process_script ( int ( * process_line ) ( const char *line ), */ static int terminate_on_exit_or_failure ( int rc ) { - /* Check and consume exit flag */ - if ( shell_exit ) { - shell_exit = 0; - return 1; - } - - return ( rc != 0 ); + return ( shell_stopped ( SHELL_STOP_COMMAND_SEQUENCE ) || + ( rc != 0 ) ); } /** @@ -292,6 +288,9 @@ static int goto_exec ( int argc, char **argv ) { return rc; } + /* Terminate processing of current command */ + shell_stop ( SHELL_STOP_COMMAND ); + return 0; } -- cgit v1.1