summaryrefslogtreecommitdiffstats
path: root/src/image/script.c
diff options
context:
space:
mode:
authorMichael Brown2010-11-22 21:20:33 +0100
committerMichael Brown2010-11-22 21:29:01 +0100
commit84aa702ff8b66f883e9ac5792b26d4e9d0760573 (patch)
tree5984913a1a1a773775adaf6ead880fefb46f3a72 /src/image/script.c
parent[script] Implement "goto" in iPXE scripts (diff)
downloadipxe-84aa702ff8b66f883e9ac5792b26d4e9d0760573.tar.gz
ipxe-84aa702ff8b66f883e9ac5792b26d4e9d0760573.tar.xz
ipxe-84aa702ff8b66f883e9ac5792b26d4e9d0760573.zip
[script] Allow "exit" to exit a script
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/image/script.c')
-rw-r--r--src/image/script.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/image/script.c b/src/image/script.c
index ba098c2c..f9d5a393 100644
--- a/src/image/script.c
+++ b/src/image/script.c
@@ -99,23 +99,20 @@ static int process_script ( int ( * process_line ) ( const char *line ),
}
/**
- * Terminate script processing if line processing failed
+ * Terminate script processing on shell exit or command failure
*
* @v rc Line processing status
* @ret terminate Terminate script processing
*/
-static int terminate_on_failure ( int rc ) {
- return ( rc != 0 );
-}
+static int terminate_on_exit_or_failure ( int rc ) {
-/**
- * Terminate script processing if line processing succeeded
- *
- * @v rc Line processing status
- * @ret terminate Terminate script processing
- */
-static int terminate_on_success ( int rc ) {
- return ( rc == 0 );
+ /* Check and consume exit flag */
+ if ( shell_exit ) {
+ shell_exit = 0;
+ return 1;
+ }
+
+ return ( rc != 0 );
}
/**
@@ -164,7 +161,7 @@ static int script_exec ( struct image *image ) {
script = image;
/* Process script */
- rc = process_script ( script_exec_line, terminate_on_failure );
+ rc = process_script ( script_exec_line, terminate_on_exit_or_failure );
/* Restore saved state, re-register image, and return */
script_offset = saved_offset;
@@ -253,6 +250,16 @@ static int goto_find_label ( const char *line ) {
}
/**
+ * Terminate script processing when label is found
+ *
+ * @v rc Line processing status
+ * @ret terminate Terminate script processing
+ */
+static int terminate_on_label_found ( int rc ) {
+ return ( rc == 0 );
+}
+
+/**
* "goto" command
*
* @v argc Argument count
@@ -280,7 +287,7 @@ static int goto_exec ( int argc, char **argv ) {
/* Find label */
saved_offset = script_offset;
if ( ( rc = process_script ( goto_find_label,
- terminate_on_success ) ) != 0 ) {
+ terminate_on_label_found ) ) != 0 ) {
script_offset = saved_offset;
return rc;
}