[syslinux:elflink] ldlinux: Pass config filename as argv[1] to ldlinux.c32

syslinux-bot for Matt Fleming matt.fleming at intel.com
Wed Feb 20 02:21:09 PST 2013


Commit-ID:  aa7dd29db684d73f044b520e8c148f7ddb8c38d5
Gitweb:     http://www.syslinux.org/commit/aa7dd29db684d73f044b520e8c148f7ddb8c38d5
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Tue, 19 Feb 2013 21:11:55 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Wed, 20 Feb 2013 10:13:10 +0000

ldlinux: Pass config filename as argv[1] to ldlinux.c32

Instead of hijacking ConfigName use a more standard method of passing
a config name to ldlinux.c32's main() function, via argc and argv.

This allows us to actually call open_config() the first time
ldlinux.c32 is executed even if the file system has already modified
ConfigName. For example, pxelinux_configfile() parses the DHCP 209
option and fills out ConfigName before ldlinux.c32 is launched, but
because the PXE code needs to do things with the path to the config
file (such as parsing the DHCP 210 option), we need to leave the
config mangling to open_config() and not try and lookup ConfigName
from ldlinux.

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

---
 com32/elflink/ldlinux/execute.c | 13 ++++++++++---
 com32/elflink/ldlinux/ldlinux.c |  8 ++------
 core/elflink/load_env32.c       |  8 ++++----
 core/include/core.h             |  2 +-
 4 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/com32/elflink/ldlinux/execute.c b/com32/elflink/ldlinux/execute.c
index c6fa8d8..ffbcf74 100644
--- a/com32/elflink/ldlinux/execute.c
+++ b/com32/elflink/ldlinux/execute.c
@@ -122,17 +122,23 @@ __export void execute(const char *cmdline, uint32_t type)
 
 		ldlinux_enter_command();
 	} else if (type == IMAGE_TYPE_CONFIG) {
-		char *argv[] = { "ldlinux.c32", NULL };
+		char *argv[] = { "ldlinux.c32", NULL, NULL };
+		char *config;
 		int rv;
 
 		/* kernel contains the config file name */
-		realpath(ConfigName, kernel, FILENAME_MAX);
+		config = malloc(FILENAME_MAX);
+		if (!config)
+			goto out;
+
+		realpath(config, kernel, FILENAME_MAX);
 
 		/* If we got anything on the command line, do a chdir */
 		if (*args)
 			mangle_name(config_cwd, args);
 
-		rv = start_ldlinux(argv);
+		argv[1] = config;
+		rv = start_ldlinux(2, argv);
 		printf("Failed to exec ldlinux.c32: %s\n", strerror(rv));
 	} else if (type == IMAGE_TYPE_LOCALBOOT) {
 		local_boot(strtoul(kernel, NULL, 0));
@@ -145,6 +151,7 @@ __export void execute(const char *cmdline, uint32_t type)
 		new_linux_kernel((char *)kernel, (char *)args);
 	}
 
+out:
 	free((void *)kernel);
 
 	/* If this returns, something went bad; return to menu */
diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index a8b1b38..92346ee 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -277,19 +277,15 @@ void ldlinux_console_init(void)
 	openconsole(&dev_stdcon_r, &dev_ansiserial_w);
 }
 
-__export int main(int argc __unused, char **argv __unused)
+__export int main(int argc __unused, char **argv)
 {
 	const void *adv;
 	const char *cmdline;
 	size_t count = 0;
-	char *config_argv[2] = { NULL, NULL };
 
 	ldlinux_console_init();
 
-	if (ConfigName[0])
-		config_argv[0] = ConfigName;
-
-	parse_configs(config_argv);
+	parse_configs(&argv[1]);
 
 	__syslinux_set_serial_console_info();
 
diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c
index c84582d..50ec266 100644
--- a/core/elflink/load_env32.c
+++ b/core/elflink/load_env32.c
@@ -59,12 +59,12 @@ void init_module_subsystem(struct elf_module *module)
     list_add(&module->list, &modules_head);
 }
 
-__export int start_ldlinux(char **argv)
+__export int start_ldlinux(int argc, char **argv)
 {
 	int rv;
 
 again:
-	rv = spawn_load(LDLINUX, 1, argv);
+	rv = spawn_load(LDLINUX, argc, argv);
 	if (rv == EEXIST) {
 		/*
 		 * If a COM32 module calls execute() we may need to
@@ -134,7 +134,7 @@ void load_env32(com32sys_t * regs __unused)
 
 	init_module_subsystem(&core_module);
 
-	start_ldlinux(argv);
+	start_ldlinux(1, argv);
 
 	/*
 	 * If we failed to load LDLINUX it could be because our
@@ -178,7 +178,7 @@ void load_env32(com32sys_t * regs __unused)
 			strcat(PATH, path);
 		}
 
-		start_ldlinux(argv);
+		start_ldlinux(1, argv);
 	}
 
 out:
diff --git a/core/include/core.h b/core/include/core.h
index a6ecbc4..d54495b 100644
--- a/core/include/core.h
+++ b/core/include/core.h
@@ -111,7 +111,7 @@ static inline void set_flags(com32sys_t *regs, uint32_t flags)
     regs->eflags.l = eflags;
 }
 
-extern int start_ldlinux(char **argv);
+extern int start_ldlinux(int argc, char **argv);
 extern int create_args_and_load(char *);
 
 extern void write_serial(char data);


More information about the Syslinux-commits mailing list