Bladeren bron

Set current working URI to be that of the executable image when

executing any image, not just a script.  (This will enable pxelinux to
use relative URIs, should it wish to.)
tags/v0.9.3
Michael Brown 17 jaren geleden
bovenliggende
commit
cfcc41d407
2 gewijzigde bestanden met toevoegingen van 13 en 12 verwijderingen
  1. 12
    3
      src/core/image.c
  2. 1
    9
      src/image/script.c

+ 12
- 3
src/core/image.c Bestand weergeven

@@ -237,6 +237,7 @@ int image_autoload ( struct image *image ) {
237 237
  * @ret rc		Return status code
238 238
  */
239 239
 int image_exec ( struct image *image ) {
240
+	struct uri *old_cwuri;
240 241
 	int rc;
241 242
 
242 243
 	/* Image must be loaded first */
@@ -252,15 +253,23 @@ int image_exec ( struct image *image ) {
252 253
 	if ( ! image->type->exec )
253 254
 		return -ENOEXEC;
254 255
 
256
+	/* Switch current working directory to be that of the image itself */
257
+	old_cwuri = uri_get ( cwuri );
258
+	churi ( image->uri );
259
+
255 260
 	/* Try executing the image */
256 261
 	if ( ( rc = image->type->exec ( image ) ) != 0 ) {
257 262
 		DBGC ( image, "IMAGE %p could not execute: %s\n",
258 263
 		       image, strerror ( rc ) );
259
-		return rc;
264
+		goto done;
260 265
 	}
261 266
 
262
-	/* Well, some formats might return... */
263
-	return 0;
267
+ done:
268
+	/* Reset current working directory */
269
+	churi ( old_cwuri );
270
+	uri_put ( old_cwuri );
271
+
272
+	return rc;
264 273
 }
265 274
 
266 275
 /**

+ 1
- 9
src/image/script.c Bestand weergeven

@@ -27,7 +27,6 @@
27 27
 #include <stdlib.h>
28 28
 #include <errno.h>
29 29
 #include <gpxe/image.h>
30
-#include <gpxe/uri.h>
31 30
 
32 31
 struct image_type script_image_type __image_type ( PROBE_NORMAL );
33 32
 
@@ -38,7 +37,6 @@ struct image_type script_image_type __image_type ( PROBE_NORMAL );
38 37
  * @ret rc		Return status code
39 38
  */
40 39
 static int script_exec ( struct image *image ) {
41
-	struct uri *old_cwuri;
42 40
 	char cmdbuf[256];
43 41
 	size_t offset = 0;
44 42
 	size_t remaining;
@@ -53,10 +51,6 @@ static int script_exec ( struct image *image ) {
53 51
 	image_get ( image );
54 52
 	unregister_image ( image );
55 53
 
56
-	/* Switch current working directory to be that of the script itself */
57
-	old_cwuri = uri_get ( cwuri );
58
-	churi ( image->uri );
59
-
60 54
 	while ( offset < image->len ) {
61 55
 	
62 56
 		/* Read up to cmdbuf bytes from script into buffer */
@@ -93,9 +87,7 @@ static int script_exec ( struct image *image ) {
93 87
 
94 88
 	rc = 0;
95 89
  done:
96
-	/* Reset current working directory, re-register image and return */
97
-	churi ( old_cwuri );
98
-	uri_put ( old_cwuri );
90
+	/* Re-register image and return */
99 91
 	register_image ( image );
100 92
 	image_put ( image );
101 93
 	return rc;

Laden…
Annuleren
Opslaan