summaryrefslogtreecommitdiffstats
path: root/src/image
diff options
context:
space:
mode:
authorMichael Brown2011-03-09 14:38:56 +0100
committerMichael Brown2011-03-09 14:38:56 +0100
commitae92700fd4594afc50f057ccb07690567327e508 (patch)
treed7e588d813e7f50211350408cbc801d806878c6f /src/image
parent[image] Move the register_and_{select|boot}_image() functions to imgmgmt.c (diff)
downloadipxe-ae92700fd4594afc50f057ccb07690567327e508.tar.gz
ipxe-ae92700fd4594afc50f057ccb07690567327e508.tar.xz
ipxe-ae92700fd4594afc50f057ccb07690567327e508.zip
[image] Generalise "currently-running script" to "currently-running image"
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/image')
-rw-r--r--src/image/script.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/image/script.c b/src/image/script.c
index 572eac71..9749b097 100644
--- a/src/image/script.c
+++ b/src/image/script.c
@@ -38,13 +38,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <usr/prompt.h>
#include <ipxe/script.h>
-/** Currently running script
- *
- * This is a global in order to allow goto_exec() to update the
- * offset.
- */
-static struct image *script;
-
/** Offset within current script
*
* This is a global in order to allow goto_exec() to update the
@@ -55,11 +48,13 @@ static size_t script_offset;
/**
* Process script lines
*
+ * @v image Script
* @v process_line Line processor
* @v terminate Termination check
* @ret rc Return status code
*/
-static int process_script ( int ( * process_line ) ( const char *line ),
+static int process_script ( struct image *image,
+ int ( * process_line ) ( const char *line ),
int ( * terminate ) ( int rc ) ) {
off_t eol;
size_t len;
@@ -70,17 +65,17 @@ static int process_script ( int ( * process_line ) ( const char *line ),
do {
/* Find length of next line, excluding any terminating '\n' */
- eol = memchr_user ( script->data, script_offset, '\n',
- ( script->len - script_offset ) );
+ eol = memchr_user ( image->data, script_offset, '\n',
+ ( image->len - script_offset ) );
if ( eol < 0 )
- eol = script->len;
+ eol = image->len;
len = ( eol - script_offset );
/* Copy line, terminate with NUL, and execute command */
{
char cmdbuf[ len + 1 ];
- copy_from_user ( cmdbuf, script->data,
+ copy_from_user ( cmdbuf, image->data,
script_offset, len );
cmdbuf[len] = '\0';
DBG ( "$ %s\n", cmdbuf );
@@ -94,7 +89,7 @@ static int process_script ( int ( * process_line ) ( const char *line ),
return rc;
}
- } while ( script_offset < script->len );
+ } while ( script_offset < image->len );
return rc;
}
@@ -138,7 +133,6 @@ static int script_exec_line ( const char *line ) {
* @ret rc Return status code
*/
static int script_exec ( struct image *image ) {
- struct image *saved_script;
size_t saved_offset;
int rc;
@@ -148,18 +142,14 @@ static int script_exec ( struct image *image ) {
unregister_image ( image );
/* Preserve state of any currently-running script */
- saved_script = script;
saved_offset = script_offset;
- /* Initialise state for this script */
- script = image;
-
/* Process script */
- rc = process_script ( script_exec_line, terminate_on_exit_or_failure );
+ rc = process_script ( image, script_exec_line,
+ terminate_on_exit_or_failure );
/* Restore saved state, re-register image, and return */
script_offset = saved_offset;
- script = saved_script;
register_image ( image );
return rc;
}
@@ -262,7 +252,7 @@ static int goto_exec ( int argc, char **argv ) {
return rc;
/* Sanity check */
- if ( ! script ) {
+ if ( ! current_image ) {
rc = -ENOTTY;
printf ( "Not in a script: %s\n", strerror ( rc ) );
return rc;
@@ -273,7 +263,7 @@ static int goto_exec ( int argc, char **argv ) {
/* Find label */
saved_offset = script_offset;
- if ( ( rc = process_script ( goto_find_label,
+ if ( ( rc = process_script ( current_image, goto_find_label,
terminate_on_label_found ) ) != 0 ) {
script_offset = saved_offset;
return rc;