Browse Source

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

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
1ae40765a6
1 changed files with 9 additions and 1 deletions
  1. 9
    1
      src/image/script.c

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

Loading…
Cancel
Save