Browse Source

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 years ago
parent
commit
cfcc41d407
2 changed files with 13 additions and 12 deletions
  1. 12
    3
      src/core/image.c
  2. 1
    9
      src/image/script.c

+ 12
- 3
src/core/image.c View File

237
  * @ret rc		Return status code
237
  * @ret rc		Return status code
238
  */
238
  */
239
 int image_exec ( struct image *image ) {
239
 int image_exec ( struct image *image ) {
240
+	struct uri *old_cwuri;
240
 	int rc;
241
 	int rc;
241
 
242
 
242
 	/* Image must be loaded first */
243
 	/* Image must be loaded first */
252
 	if ( ! image->type->exec )
253
 	if ( ! image->type->exec )
253
 		return -ENOEXEC;
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
 	/* Try executing the image */
260
 	/* Try executing the image */
256
 	if ( ( rc = image->type->exec ( image ) ) != 0 ) {
261
 	if ( ( rc = image->type->exec ( image ) ) != 0 ) {
257
 		DBGC ( image, "IMAGE %p could not execute: %s\n",
262
 		DBGC ( image, "IMAGE %p could not execute: %s\n",
258
 		       image, strerror ( rc ) );
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 View File

27
 #include <stdlib.h>
27
 #include <stdlib.h>
28
 #include <errno.h>
28
 #include <errno.h>
29
 #include <gpxe/image.h>
29
 #include <gpxe/image.h>
30
-#include <gpxe/uri.h>
31
 
30
 
32
 struct image_type script_image_type __image_type ( PROBE_NORMAL );
31
 struct image_type script_image_type __image_type ( PROBE_NORMAL );
33
 
32
 
38
  * @ret rc		Return status code
37
  * @ret rc		Return status code
39
  */
38
  */
40
 static int script_exec ( struct image *image ) {
39
 static int script_exec ( struct image *image ) {
41
-	struct uri *old_cwuri;
42
 	char cmdbuf[256];
40
 	char cmdbuf[256];
43
 	size_t offset = 0;
41
 	size_t offset = 0;
44
 	size_t remaining;
42
 	size_t remaining;
53
 	image_get ( image );
51
 	image_get ( image );
54
 	unregister_image ( image );
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
 	while ( offset < image->len ) {
54
 	while ( offset < image->len ) {
61
 	
55
 	
62
 		/* Read up to cmdbuf bytes from script into buffer */
56
 		/* Read up to cmdbuf bytes from script into buffer */
93
 
87
 
94
 	rc = 0;
88
 	rc = 0;
95
  done:
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
 	register_image ( image );
91
 	register_image ( image );
100
 	image_put ( image );
92
 	image_put ( image );
101
 	return rc;
93
 	return rc;

Loading…
Cancel
Save