summaryrefslogtreecommitdiffstats
path: root/src/image
diff options
context:
space:
mode:
authorMichael Brown2007-08-02 21:27:19 +0200
committerMichael Brown2007-08-02 21:27:19 +0200
commit1ae40765a665244804891d9c3c6ed95e0f641ad9 (patch)
treecba484068e2703387ad5b1465740bc8b136e8602 /src/image
parenturi_get(NULL) and uri_put(NULL) are explicitly allowed. (diff)
downloadipxe-1ae40765a665244804891d9c3c6ed95e0f641ad9.tar.gz
ipxe-1ae40765a665244804891d9c3c6ed95e0f641ad9.tar.xz
ipxe-1ae40765a665244804891d9c3c6ed95e0f641ad9.zip
Set current working URI equal to script URI during script execution.
Diffstat (limited to 'src/image')
-rw-r--r--src/image/script.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/image/script.c b/src/image/script.c
index c8821522..2f159c97 100644
--- a/src/image/script.c
+++ b/src/image/script.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <errno.h>
#include <gpxe/image.h>
+#include <gpxe/uri.h>
struct image_type script_image_type __image_type ( PROBE_NORMAL );
@@ -37,6 +38,7 @@ struct image_type script_image_type __image_type ( PROBE_NORMAL );
* @ret rc Return status code
*/
static int script_exec ( struct image *image ) {
+ struct uri *old_cwuri;
char cmdbuf[256];
size_t offset = 0;
size_t remaining;
@@ -51,6 +53,10 @@ static int script_exec ( struct image *image ) {
image_get ( image );
unregister_image ( image );
+ /* Switch current working directory to be that of the script itself */
+ old_cwuri = uri_get ( cwuri );
+ churi ( image->uri );
+
while ( offset < image->len ) {
/* Read up to cmdbuf bytes from script into buffer */
@@ -87,7 +93,9 @@ static int script_exec ( struct image *image ) {
rc = 0;
done:
- /* Re-register image and return */
+ /* Reset current working directory, re-register image and return */
+ churi ( old_cwuri );
+ uri_put ( old_cwuri );
register_image ( image );
image_put ( image );
return rc;