[syslinux:elflink] module: Stop silently failing to load dependency modules

syslinux-bot for Matt Fleming matt.fleming at intel.com
Thu Nov 29 05:33:07 PST 2012


Commit-ID:  8f1c64acf9c60d184fef37f373737895468c0771
Gitweb:     http://www.syslinux.org/commit/8f1c64acf9c60d184fef37f373737895468c0771
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Thu, 29 Nov 2012 11:35:28 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Thu, 29 Nov 2012 13:30:16 +0000

module: Stop silently failing to load dependency modules

We should be checking the return value of spawn_load() when loading a
module's dependencies and printing some kind of an error message if
they fail to load (for instance if the file is missing) and returning
an error to the caller.

Track the most recently loaded module in 'head' before we begin
loading dependencies. That way we can unload any dependencies in the
error path that were successfully loaded.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/lib/sys/module/elf_module.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index c92fe26..8a8ed20 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -492,6 +492,7 @@ int module_load(struct elf_module *module) {
 	Elf32_Sym *main_sym;
 	Elf32_Ehdr elf_hdr;
 	module_ctor_t *ctor;
+	struct elf_module *head = NULL;
 
 	// Do not allow duplicate modules
 	if (module_find(module->name) != NULL) {
@@ -525,6 +526,8 @@ int module_load(struct elf_module *module) {
 	CHECKED(res, prepare_dynlinking(module), error);
 	//printf("check... 4\n");
 
+	head =  list_entry(&modules_head, typeof(*head), list);
+
 	/* Find modules we need to load as dependencies */
 	if (module->str_table) {
 		int i;
@@ -550,7 +553,11 @@ int module_load(struct elf_module *module) {
 				p = dep;
 
 			argv[0] = p;
-			spawn_load(p, 1, argv);
+			res = spawn_load(p, 1, argv);
+			if (res < 0) {
+				printf("Failed to load %s\n", p);
+				goto error;
+			}
 		}
 	}
 
@@ -595,6 +602,9 @@ int module_load(struct elf_module *module) {
 	return 0;
 
 error:
+	if (head)
+		unload_modules_since(head->name);
+
 	// Remove the module from the module list (if applicable)
 	list_del_init(&module->list);
 


More information about the Syslinux-commits mailing list