|
@@ -44,6 +44,13 @@ static int script_exec ( struct image *image ) {
|
44
|
44
|
char *eol;
|
45
|
45
|
int rc;
|
46
|
46
|
|
|
47
|
+ /* Temporarily de-register image, so that a "boot" command
|
|
48
|
+ * doesn't throw us into an execution loop. Hold a reference
|
|
49
|
+ * to avoid the image's being freed.
|
|
50
|
+ */
|
|
51
|
+ image_get ( image );
|
|
52
|
+ unregister_image ( image );
|
|
53
|
+
|
47
|
54
|
while ( offset < image->len ) {
|
48
|
55
|
|
49
|
56
|
/* Read up to cmdbuf bytes from script into buffer */
|
|
@@ -60,7 +67,8 @@ static int script_exec ( struct image *image ) {
|
60
|
67
|
if ( ! eol ) {
|
61
|
68
|
DBG ( "Script line too long (max %d bytes)\n",
|
62
|
69
|
sizeof ( cmdbuf ) );
|
63
|
|
- return -ENOEXEC;
|
|
70
|
+ rc = -ENOEXEC;
|
|
71
|
+ goto done;
|
64
|
72
|
}
|
65
|
73
|
|
66
|
74
|
/* Mark end of line and execute command */
|
|
@@ -69,14 +77,19 @@ static int script_exec ( struct image *image ) {
|
69
|
77
|
if ( ( rc = system ( cmdbuf ) ) != 0 ) {
|
70
|
78
|
DBG ( "Command \"%s\" exited with status %d\n",
|
71
|
79
|
cmdbuf, rc );
|
72
|
|
- return rc;
|
|
80
|
+ goto done;
|
73
|
81
|
}
|
74
|
82
|
|
75
|
83
|
/* Move to next line */
|
76
|
84
|
offset += ( ( eol - cmdbuf ) + 1 );
|
77
|
85
|
}
|
78
|
86
|
|
79
|
|
- return 0;
|
|
87
|
+ rc = 0;
|
|
88
|
+ done:
|
|
89
|
+ /* Re-register image and return */
|
|
90
|
+ register_image ( image );
|
|
91
|
+ image_put ( image );
|
|
92
|
+ return rc;
|
80
|
93
|
}
|
81
|
94
|
|
82
|
95
|
/**
|