* @ret rc Return status code
*/
int image_exec ( struct image *image ) {
+ struct uri *old_cwuri;
int rc;
/* Image must be loaded first */
if ( ! image->type->exec )
return -ENOEXEC;
+ /* Switch current working directory to be that of the image itself */
+ old_cwuri = uri_get ( cwuri );
+ churi ( image->uri );
+
/* Try executing the image */
if ( ( rc = image->type->exec ( image ) ) != 0 ) {
DBGC ( image, "IMAGE %p could not execute: %s\n",
image, strerror ( rc ) );
- return rc;
+ goto done;
}
- /* Well, some formats might return... */
- return 0;
+ done:
+ /* Reset current working directory */
+ churi ( old_cwuri );
+ uri_put ( old_cwuri );
+
+ return rc;
}
/**
#include <stdlib.h>
#include <errno.h>
#include <gpxe/image.h>
-#include <gpxe/uri.h>
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;
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 */
rc = 0;
done:
- /* Reset current working directory, re-register image and return */
- churi ( old_cwuri );
- uri_put ( old_cwuri );
+ /* Re-register image and return */
register_image ( image );
image_put ( image );
return rc;