summaryrefslogtreecommitdiffstats
path: root/discover/grub2
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-11-27 19:51:49 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-11-27 20:02:30 +0800
commit9e5b77f258b8e993f480763d8e5269bd8c87b508 (patch)
tree6e802cf451fe385f67e51e89d423fdb6cf2a1116 /discover/grub2
parent77e0df22dd3fb1cf0dcdd1124a5aafa2ec872a1f (diff)
downloadtalos-petitboot-9e5b77f258b8e993f480763d8e5269bd8c87b508.tar.gz
talos-petitboot-9e5b77f258b8e993f480763d8e5269bd8c87b508.zip
discover/grub2: Populate $prefix from config file location
Rather than always using the default prefix, we should determine it from the location of the grub2 config file. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/grub2')
-rw-r--r--discover/grub2/grub2.c2
-rw-r--r--discover/grub2/grub2.h4
-rw-r--r--discover/grub2/parser.y5
-rw-r--r--discover/grub2/script.c18
4 files changed, 24 insertions, 5 deletions
diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c
index ffb6ece..7f63c35 100644
--- a/discover/grub2/grub2.c
+++ b/discover/grub2/grub2.c
@@ -103,7 +103,7 @@ static int grub2_parse(struct discover_context *dc)
continue;
parser = grub2_parser_create(dc);
- grub2_parser_parse(parser, buf, len);
+ grub2_parser_parse(parser, *filename, buf, len);
talloc_free(buf);
talloc_free(parser);
break;
diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h
index 1515d69..6166289 100644
--- a/discover/grub2/grub2.h
+++ b/discover/grub2/grub2.h
@@ -89,6 +89,7 @@ struct grub2_script {
struct list symtab;
struct discover_context *ctx;
struct discover_boot_option *opt;
+ const char *filename;
unsigned int n_options;
};
@@ -176,6 +177,7 @@ bool resolve_grub2_resource(struct device_handler *handler,
/* external parser api */
struct grub2_parser *grub2_parser_create(struct discover_context *ctx);
-void grub2_parser_parse(struct grub2_parser *parser, char *buf, int len);
+void grub2_parser_parse(struct grub2_parser *parser, const char *filename,
+ char *buf, int len);
#endif /* GRUB2_H */
diff --git a/discover/grub2/parser.y b/discover/grub2/parser.y
index a3473ca..5a4d4f8 100644
--- a/discover/grub2/parser.y
+++ b/discover/grub2/parser.y
@@ -303,11 +303,14 @@ struct grub2_parser *grub2_parser_create(struct discover_context *ctx)
return parser;
}
-void grub2_parser_parse(struct grub2_parser *parser, char *buf, int len)
+void grub2_parser_parse(struct grub2_parser *parser, const char *filename,
+ char *buf, int len)
{
YY_BUFFER_STATE bufstate;
int rc;
+ parser->script->filename = filename;
+
bufstate = yy_scan_bytes(buf, len - 1, parser->scanner);
yyset_lineno(1, parser->scanner);
diff --git a/discover/grub2/script.c b/discover/grub2/script.c
index e29d437..a58f1a0 100644
--- a/discover/grub2/script.c
+++ b/discover/grub2/script.c
@@ -400,12 +400,26 @@ int statement_function_execute(struct grub2_script *script,
static void init_env(struct grub2_script *script)
{
struct env_entry *env;
+ char *prefix, *sep;
list_init(&script->environment);
+ /* use location of the parsed config file to determine the prefix */
env = talloc(script, struct env_entry);
+
+ prefix = NULL;
+ if (script->filename) {
+ sep = strrchr(script->filename, '/');
+ if (sep)
+ prefix = talloc_strndup(env, script->filename,
+ sep - script->filename);
+ }
+
env->name = talloc_strdup(env, "prefix");
- env->value = talloc_strdup(env, default_prefix);
+ if (prefix)
+ env->value = prefix;
+ else
+ env->value = talloc_strdup(env, default_prefix);
list_add(&script->environment, &env->list);
}
@@ -426,6 +440,7 @@ void script_register_function(struct grub2_script *script,
void script_execute(struct grub2_script *script)
{
+ init_env(script);
statements_execute(script, script->statements);
}
@@ -436,7 +451,6 @@ struct grub2_script *create_script(struct grub2_parser *parser,
script = talloc_zero(parser, struct grub2_script);
- init_env(script);
script->ctx = ctx;
list_init(&script->symtab);
OpenPOWER on IntegriCloud