summaryrefslogtreecommitdiffstats
path: root/discover/grub2/script.c
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/script.c
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/script.c')
-rw-r--r--discover/grub2/script.c18
1 files changed, 16 insertions, 2 deletions
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