summaryrefslogtreecommitdiffstats
path: root/src/core/image.c
diff options
context:
space:
mode:
authorMichael Brown2012-07-20 13:36:41 +0200
committerMichael Brown2012-07-20 13:45:15 +0200
commit5d3c368efbc23d0e85e7bb3fa20c3766bfafd88a (patch)
tree3fc7bc18dc96317acbd55ba7fecc8c956507b7d8 /src/core/image.c
parent[image] Add "--autofree" option (diff)
downloadipxe-5d3c368efbc23d0e85e7bb3fa20c3766bfafd88a.tar.gz
ipxe-5d3c368efbc23d0e85e7bb3fa20c3766bfafd88a.tar.xz
ipxe-5d3c368efbc23d0e85e7bb3fa20c3766bfafd88a.zip
[image] Add "--replace" option
Expose image tail-recursion to iPXE scripts via the "--replace" option. This functions similarly to exec() under Unix: the currently-executing script is replaced with the new image (as opposed to running the new image as a subroutine). Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/image.c')
-rw-r--r--src/core/image.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/core/image.c b/src/core/image.c
index 666ee3de..1bf5447f 100644
--- a/src/core/image.c
+++ b/src/core/image.c
@@ -327,6 +327,14 @@ int image_exec ( struct image *image ) {
if ( image->flags & IMAGE_AUTO_UNREGISTER )
unregister_image ( image );
+ /* Debug message for tail-recursion. Placed here because the
+ * image_put() may end up freeing the image.
+ */
+ if ( replacement ) {
+ DBGC ( image, "IMAGE %s replacing self with IMAGE %s\n",
+ image->name, replacement->name );
+ }
+
/* Drop temporary reference to the original image */
image_put ( image );
@@ -338,12 +346,8 @@ int image_exec ( struct image *image ) {
uri_put ( old_cwuri );
/* Tail-recurse into replacement image, if one exists */
- if ( replacement ) {
- DBGC ( image, "IMAGE <freed> replacing self with IMAGE %s\n",
- replacement->name );
- if ( ( rc = image_exec ( replacement ) ) != 0 )
- return rc;
- }
+ if ( replacement )
+ return image_exec ( replacement );
return rc;
}