aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFeng Tang <feng.tang@intel.com>2010-08-26 16:39:26 +0800
committerFeng Tang <feng.tang@intel.com>2010-08-26 16:44:15 +0800
commitaa4cc23e81efbdf8de05804fe14413a79fdef450 (patch)
treeb935658ce90b1695f902802a3019805b6f2537dc
parent56b063adca570ab5af63338cf796f99861d7231c (diff)
downloadbak.git-aa4cc23e81efbdf8de05804fe14413a79fdef450.tar.gz
bak.git-aa4cc23e81efbdf8de05804fe14413a79fdef450.tar.xz
bak.git-aa4cc23e81efbdf8de05804fe14413a79fdef450.zip
elflink: add a load_default_config()HEADelflink
which will search and parse the default config files for extlinux/isolinux, not including pxelinux yet. With that, we can remove each fs's load_config hook, just using global parsing code Signed-off-by: Feng Tang <feng.tang@intel.com>
-rw-r--r--core/elflink/readconfig.c75
1 files changed, 51 insertions, 24 deletions
diff --git a/core/elflink/readconfig.c b/core/elflink/readconfig.c
index 39b5d125..c984fa80 100644
--- a/core/elflink/readconfig.c
+++ b/core/elflink/readconfig.c
@@ -22,6 +22,8 @@
#include <com32.h>
#include <syslinux/adv.h>
#include <syslinux/config.h>
+#include <fs.h>
+#include <core.h>
#include "menu.h"
@@ -1044,31 +1046,56 @@ do_include:
static int parse_one_config(const char *filename)
{
FILE *f;
- int i;
-
- /*
- if (!strcmp(filename, "~"))
- filename = syslinux_config_file();
- */
- f = fopen(filename, "r");
- if (f)
- goto config_found;
+ if (filename) {
+ f = fopen(filename, "r");
+ if (f) {
+ parse_config_file(f);
+ fclose(f);
+ return 0;
+ }
+ }
- /* force to use hard coded config file name */
- f = fopen("extlinux.conf", "r");
- if (f)
- goto config_found;
+ return -1;
+}
- f = fopen("isolinux.cfg", "r");
- if (f)
- goto config_found;
+int load_default_config(void)
+{
+ char name_buf[FILENAME_MAX];
+ char fname[FILENAME_MAX];
+ const char *sd, **sdp;
+ const char *sf, **sfp;
+
+ static const char *def_dirs[] = {
+ "/boot/isolinux",
+ "/isolinux",
+ "/boot/syslinux",
+ "/syslinux",
+ "/",
+ NULL
+ };
+ static const char *def_files[] = {
+ "isolinux.cfg",
+ "extlinux.conf",
+ "syslinux.cfg",
+ NULL
+ };
+
+ for (sdp = def_dirs; (sd = *sdp); sdp++) {
+ for (sfp = def_files; (sf = *sfp); sfp++) {
+ snprintf(name_buf, sizeof name_buf,
+ "%s%s%s",
+ sd, (*sd && sd[strlen(sd)-1] == '/') ? "" : "/",
+ sf);
+ realpath(fname, name_buf, FILENAME_MAX);
+ mp("search: %s", fname);
+
+ if (!parse_one_config(fname))
+ return 0; /* success */
+ }
+ }
return -1;
-config_found:
- parse_config_file(f);
- fclose(f);
- return 0;
}
static void resolve_gotos(void)
@@ -1128,12 +1155,12 @@ void parse_configs(char **argv)
/* Actually process the files */
current_menu = root_menu;
- if (!argv || !*argv) {
- parse_one_config("~");
- } else {
+ if (!argv || !*argv)
+ load_default_config();
+ else {
while ((filename = *argv++)) {
mp("Parsing config: %s", filename);
- parse_one_config(filename);
+ parse_one_config(filename);
}
}