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