[syslinux] [PATCH 08/12] elflink: Don't reload the current EXEC_MODULE module

Matt Fleming matt at console-pimps.org
Wed Mar 9 08:00:19 PST 2011


From: Matt Fleming <matt.fleming at linux.intel.com>

As the ldlinux.c32 ELF module is an executable (EXEC_MODULE) and not a
library (LIB_MODULE), we need to make sure we don't reload it when
another executable wants to resolve a symbol exported by ldlinux.

Whenever an EXEC_MODULE module is loaded its MODULE_MAIN function is
executed. In the case of ldlinux, the MODULE_MAIN function drops the
user at a command line. So, what currently happens is that if we load
an executable module, say menu.c32, which needs symbols exported by
ldlinux and ldlinux is already loaded and running, we'll reload
ldlinux when resolving undefined symbols from menu.c32 and end up
dropping the user at a command prompt and _not_ resolve the symbols
and return control to menu.c32's MODULE_MAIN function. ldlinux.c32
effectively steals control of the proces.

Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com>
---
 com32/lib/sys/module/exec.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c
index 0e7aa3f..03d11cb 100644
--- a/com32/lib/sys/module/exec.c
+++ b/com32/lib/sys/module/exec.c
@@ -237,11 +237,23 @@ int spawn_load(const char *name,const char **argv)
 	if (module == NULL)
 		return -1;
 
-	/* ugly hack to reload the same module */
 	if (!strcmp(cur_module->name, module->name)) {
 		mp("We is running this module %s already!", module->name);
-		module_unload(cur_module);
-		cur_module = NULL;
+
+		/*
+		 * If we're already running the module and it's of
+		 * type EXEC_MODULE, then just return. We don't reload
+		 * the module because that might cause us to re-run
+		 * the init functions, which will cause us to run the
+		 * MODULE_MAIN function, which will take control of
+		 * this process.
+		 *
+		 * This can happen if some other EXEC_MODULE is
+		 * resolving a symbol that is exported by the current
+		 * EXEC_MODULE.
+		 */
+		if (get_module_type(module) == EXEC_MODULE)
+			return 0;
 	}
 
 	res = module_load(module);
-- 
1.7.4




More information about the Syslinux mailing list