Переглянути джерело

Scripts temporarily deregister themselves while executing. This

allows us to avoid execution loops without having to hack around the
image registration order.
tags/v0.9.3
Michael Brown 17 роки тому
джерело
коміт
b256900d4f
3 змінених файлів з 18 додано та 18 видалено
  1. 0
    14
      src/core/image.c
  2. 16
    3
      src/image/script.c
  3. 2
    1
      src/usr/imgmgmt.c

+ 0
- 14
src/core/image.c Переглянути файл

@@ -106,20 +106,6 @@ void unregister_image ( struct image *image ) {
106 106
 	DBGC ( image, "IMAGE %p unregistered\n", image );
107 107
 }
108 108
 
109
-/**
110
- * Move image to start of list of registered images
111
- *
112
- * @v image		Executable/loadable image
113
- *
114
- * Move the image to the start of the image list.  This makes it
115
- * easier to keep track of which of the images marked as loaded is
116
- * likely to still be valid.
117
- */
118
-void promote_image ( struct image *image ) {
119
-	list_del ( &image->list );
120
-	list_add ( &image->list, &images );
121
-}
122
-
123 109
 /**
124 110
  * Find image by name
125 111
  *

+ 16
- 3
src/image/script.c Переглянути файл

@@ -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
 /**

+ 2
- 1
src/usr/imgmgmt.c Переглянути файл

@@ -89,7 +89,8 @@ int imgload ( struct image *image ) {
89 89
 		return rc;
90 90
 
91 91
 	/* If we succeed, move the image to the start of the list */
92
-	promote_image ( image );
92
+#warning "No longer exists"
93
+	//	promote_image ( image );
93 94
 
94 95
 	return 0;
95 96
 }

Завантаження…
Відмінити
Зберегти