diff options
author | Michael Brown | 2012-07-20 11:37:24 +0200 |
---|---|---|
committer | Michael Brown | 2012-07-20 13:44:40 +0200 |
commit | d3c660b6718c8d85b34d5c7ca8c4ed12659e1cc7 (patch) | |
tree | c2c20f097fc46b59a02a903186fc1f9c30fa89cc /src/core/image.c | |
parent | [libc] Add missing wchar.h header (diff) | |
download | ipxe-d3c660b6718c8d85b34d5c7ca8c4ed12659e1cc7.tar.gz ipxe-d3c660b6718c8d85b34d5c7ca8c4ed12659e1cc7.tar.xz ipxe-d3c660b6718c8d85b34d5c7ca8c4ed12659e1cc7.zip |
[image] Add "--autofree" option
Allow images to be automatically freed after execution completes
(successfully or otherwise).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/image.c')
-rw-r--r-- | src/core/image.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/core/image.c b/src/core/image.c index bf9bb7fa..666ee3de 100644 --- a/src/core/image.c +++ b/src/core/image.c @@ -194,6 +194,10 @@ int register_image ( struct image *image ) { */ void unregister_image ( struct image *image ) { + /* Do nothing unless image is registered */ + if ( ! ( image->flags & IMAGE_REGISTERED ) ) + return; + DBGC ( image, "IMAGE %s unregistered\n", image->name ); list_del ( &image->list ); image->flags &= ~IMAGE_REGISTERED; @@ -259,23 +263,13 @@ int image_probe ( struct image *image ) { */ int image_exec ( struct image *image ) { struct image *saved_current_image; - struct image *replacement; + struct image *replacement = NULL; struct uri *old_cwuri; int rc; /* Sanity check */ assert ( image->flags & IMAGE_REGISTERED ); - /* Check that this image can be selected for execution */ - if ( ( rc = image_select ( image ) ) != 0 ) - return rc; - - /* Check that image is trusted (if applicable) */ - if ( require_trusted_images && ! ( image->flags & IMAGE_TRUSTED ) ) { - DBGC ( image, "IMAGE %s is not trusted\n", image->name ); - return -EACCES_UNTRUSTED; - } - /* Switch current working directory to be that of the image itself */ old_cwuri = uri_get ( cwuri ); churi ( image->uri ); @@ -289,6 +283,17 @@ int image_exec ( struct image *image ) { */ current_image = image_get ( image ); + /* Check that this image can be selected for execution */ + if ( ( rc = image_select ( image ) ) != 0 ) + goto err; + + /* Check that image is trusted (if applicable) */ + if ( require_trusted_images && ! ( image->flags & IMAGE_TRUSTED ) ) { + DBGC ( image, "IMAGE %s is not trusted\n", image->name ); + rc = -EACCES_UNTRUSTED; + goto err; + } + /* Record boot attempt */ syslog ( LOG_NOTICE, "Executing \"%s\"\n", image->name ); @@ -317,6 +322,11 @@ int image_exec ( struct image *image ) { if ( replacement ) assert ( replacement->flags & IMAGE_REGISTERED ); + err: + /* Unregister image if applicable */ + if ( image->flags & IMAGE_AUTO_UNREGISTER ) + unregister_image ( image ); + /* Drop temporary reference to the original image */ image_put ( image ); |