david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Set current working URI equal to script URI during script execution.

This commit is contained in:
Michael Brown 2007-08-02 20:27:19 +01:00
parent 49009a4c1b
commit 1ae40765a6
1 changed files with 9 additions and 1 deletions

View File

@ -27,6 +27,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <gpxe/image.h> #include <gpxe/image.h>
#include <gpxe/uri.h>
struct image_type script_image_type __image_type ( PROBE_NORMAL ); 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 * @ret rc Return status code
*/ */
static int script_exec ( struct image *image ) { static int script_exec ( struct image *image ) {
struct uri *old_cwuri;
char cmdbuf[256]; char cmdbuf[256];
size_t offset = 0; size_t offset = 0;
size_t remaining; size_t remaining;
@ -51,6 +53,10 @@ static int script_exec ( struct image *image ) {
image_get ( image ); image_get ( image );
unregister_image ( 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 ) { while ( offset < image->len ) {
/* Read up to cmdbuf bytes from script into buffer */ /* Read up to cmdbuf bytes from script into buffer */
@ -87,7 +93,9 @@ static int script_exec ( struct image *image ) {
rc = 0; rc = 0;
done: 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 ); register_image ( image );
image_put ( image ); image_put ( image );
return rc; return rc;