X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=discover%2Fgrub2%2Fscript.c;h=a58f1a0f58eccb51abee06f9127ca0ac30450091;hb=9e5b77f258b8e993f480763d8e5269bd8c87b508;hp=e29d43702b1e0099435ab76b2f3966ad559cee90;hpb=59dbd08e2a8354e71578c0d7ca2283951a384801;p=petitboot 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);