summaryrefslogtreecommitdiffstats
path: root/src/image/script.c
diff options
context:
space:
mode:
authorMichael Brown2007-06-09 20:00:34 +0200
committerMichael Brown2007-06-09 20:00:34 +0200
commitb256900d4f6fe187cb93ed91bbf12c723e6b9364 (patch)
treef1fb4b41383c157e48e37d7f3d9b55ea3ee042ee /src/image/script.c
parentAllow xfer_open() to take a struct uri as well as a URI string. (diff)
downloadipxe-b256900d4f6fe187cb93ed91bbf12c723e6b9364.tar.gz
ipxe-b256900d4f6fe187cb93ed91bbf12c723e6b9364.tar.xz
ipxe-b256900d4f6fe187cb93ed91bbf12c723e6b9364.zip
Scripts temporarily deregister themselves while executing. This
allows us to avoid execution loops without having to hack around the image registration order.
Diffstat (limited to 'src/image/script.c')
-rw-r--r--src/image/script.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/image/script.c b/src/image/script.c
index 84432435..8e511d21 100644
--- a/src/image/script.c
+++ b/src/image/script.c
@@ -44,6 +44,13 @@ static int script_exec ( struct image *image ) {
char *eol;
int rc;
+ /* Temporarily de-register image, so that a "boot" command
+ * doesn't throw us into an execution loop. Hold a reference
+ * to avoid the image's being freed.
+ */
+ image_get ( image );
+ unregister_image ( image );
+
while ( offset < image->len ) {
/* Read up to cmdbuf bytes from script into buffer */
@@ -60,7 +67,8 @@ static int script_exec ( struct image *image ) {
if ( ! eol ) {
DBG ( "Script line too long (max %d bytes)\n",
sizeof ( cmdbuf ) );
- return -ENOEXEC;
+ rc = -ENOEXEC;
+ goto done;
}
/* Mark end of line and execute command */
@@ -69,14 +77,19 @@ static int script_exec ( struct image *image ) {
if ( ( rc = system ( cmdbuf ) ) != 0 ) {
DBG ( "Command \"%s\" exited with status %d\n",
cmdbuf, rc );
- return rc;
+ goto done;
}
/* Move to next line */
offset += ( ( eol - cmdbuf ) + 1 );
}
- return 0;
+ rc = 0;
+ done:
+ /* Re-register image and return */
+ register_image ( image );
+ image_put ( image );
+ return rc;
}
/**