]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
Scripts temporarily deregister themselves while executing. This
authorMichael Brown <mcb30@etherboot.org>
Sat, 9 Jun 2007 18:00:34 +0000 (19:00 +0100)
committerMichael Brown <mcb30@etherboot.org>
Sat, 9 Jun 2007 18:00:34 +0000 (19:00 +0100)
allows us to avoid execution loops without having to hack around the
image registration order.

src/core/image.c
src/image/script.c
src/usr/imgmgmt.c

index e270540aab02fc6ce2372b3ab423ab23aef2d97b..08a129ffa700f86f53018e1af1146c570c7491d4 100644 (file)
@@ -106,20 +106,6 @@ void unregister_image ( struct image *image ) {
        DBGC ( image, "IMAGE %p unregistered\n", image );
 }
 
-/**
- * Move image to start of list of registered images
- *
- * @v image            Executable/loadable image
- *
- * Move the image to the start of the image list.  This makes it
- * easier to keep track of which of the images marked as loaded is
- * likely to still be valid.
- */
-void promote_image ( struct image *image ) {
-       list_del ( &image->list );
-       list_add ( &image->list, &images );
-}
-
 /**
  * Find image by name
  *
index 844324350f3f78dfc69f45cdd2b02f6033067797..8e511d2113f4e082e8fab6609bc221270549d0da 100644 (file)
@@ -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;
 }
 
 /**
index 28801fe85aee55716d27d115178e4316a1e3672b..9fe2e1493a156652c1fc584d92c57488623ab8fd 100644 (file)
@@ -89,7 +89,8 @@ int imgload ( struct image *image ) {
                return rc;
 
        /* If we succeed, move the image to the start of the list */
-       promote_image ( image );
+#warning "No longer exists"
+       //      promote_image ( image );
 
        return 0;
 }