[syslinux:elflink] ldlinux: fix INCLUDE regression

syslinux-bot for Matt Fleming matt.fleming at intel.com
Thu Jun 27 05:15:04 PDT 2013


Commit-ID:  00d0f3add99de6d9c83ff2492bac175a5e1b8a11
Gitweb:     http://www.syslinux.org/commit/00d0f3add99de6d9c83ff2492bac175a5e1b8a11
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Thu, 27 Jun 2013 12:54:15 +0100
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Thu, 27 Jun 2013 13:03:30 +0100

ldlinux: fix INCLUDE regression

We don't want to overwrite 'ConfigName' when parsing a config file via
the INCLUDE directive, which commit 5447ef821 ("ldlinux: Always update
ConfigName when opening a config file") failed to take into account. In
the INCLUDE case we're only parsing config fragments, and not a main
config file.

Rename parse_one_config() to parse_main_config() to more accurately
reflect when it should be invoked (i.e. not for INCLUDE).

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

---
 com32/elflink/ldlinux/readconfig.c | 92 +++++++++++++++++++++++++++++---------
 1 file changed, 70 insertions(+), 22 deletions(-)

diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c
index 3ee825d..22efbe4 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -640,7 +640,7 @@ extern const char *append;
 extern uint16_t PXERetry;
 static struct labeldata ld;
 
-static int parse_one_config(const char *filename);
+static int parse_main_config(const char *filename);
 
 static char *is_kernel_type(char *cmdstr, enum kernel_type *type)
 {
@@ -810,6 +810,70 @@ bail:
     return -1;
 }
 
+static void parse_config_file(FILE * f);
+
+static void do_include_menu(char *str, struct menu *m)
+{
+    const char *file;
+    char *p;
+    FILE *f;
+    int fd;
+
+    p = skipspace(str);
+    file = refdup_word(&p);
+    p = skipspace(p);
+
+    fd = open(file, O_RDONLY);
+    if (fd < 0)
+	goto put;
+
+    f = fdopen(fd, "r");
+    if (!f)
+	goto bail;
+
+    if (*p) {
+	record(m, &ld, append);
+	m = current_menu = begin_submenu(p);
+    }
+
+    parse_config_file(f);
+
+    if (*p) {
+	record(m, &ld, append);
+	m = current_menu = end_submenu();
+    }
+
+bail:
+    close(fd);
+put:
+    refstr_put(file);
+
+}
+
+static void do_include(char *str)
+{
+    const char *file;
+    char *p;
+    FILE *f;
+    int fd;
+
+    p = skipspace(str);
+    file = refdup_word(&p);
+
+    fd = open(file, O_RDONLY);
+    if (fd < 0)
+	goto put;
+
+    f = fdopen(fd, "r");
+    if (f)
+	parse_config_file(f);
+
+bail:
+    close(fd);
+put:
+    refstr_put(file);
+}
+
 static void parse_config_file(FILE * f)
 {
     char line[MAX_LINE], *p, *ep, ch;
@@ -898,7 +962,7 @@ static void parse_config_file(FILE * f)
 		    m->menu_master_passwd = refstrdup(skipspace(p + 6));
 		}
 	    } else if ((ep = looking_at(p, "include"))) {
-		goto do_include;
+		do_include_menu(ep, m);
 	    } else if ((ep = looking_at(p, "background"))) {
 		p = skipspace(ep);
 		refstr_put(m->menu_background);
@@ -1095,23 +1159,7 @@ static void parse_config_file(FILE * f)
 		m->fkeyhelp[fkeyno].background = refdup_word(&p);
 	    }
 	} else if ((ep = looking_at(p, "include"))) {
-do_include:
-	    {
-		const char *file;
-		p = skipspace(ep);
-		file = refdup_word(&p);
-		p = skipspace(p);
-		if (*p) {
-		    record(m, &ld, append);
-		    m = current_menu = begin_submenu(p);
-		    parse_one_config(file);
-		    record(m, &ld, append);
-		    m = current_menu = end_submenu();
-		} else {
-		    parse_one_config(file);
-		}
-		refstr_put(file);
-	    }
+	    do_include(ep);
 	} else if (looking_at(p, "append")) {
 	    const char *a = refstrdup(skipspace(p + 6));
 	    if (ld.label) {
@@ -1386,7 +1434,7 @@ do_include:
     }
 }
 
-static int parse_one_config(const char *filename)
+static int parse_main_config(const char *filename)
 {
 	const char *mode = "r";
 	FILE *f;
@@ -1466,14 +1514,14 @@ void parse_configs(char **argv)
     current_menu = root_menu;
 
     if (!argv || !*argv) {
-	if (parse_one_config(NULL) < 0) {
+	if (parse_main_config(NULL) < 0) {
 	    printf("WARNING: No configuration file found\n");
 	    return;
 	}
     } else {
 	while ((filename = *argv++)) {
 		dprintf("Parsing config: %s", filename);
-	    parse_one_config(filename);
+	    parse_main_config(filename);
 	}
     }
 


More information about the Syslinux-commits mailing list