]> git.ozlabs.org Git - petitboot/blobdiff - discover/grub2/script.c
discover: remove register_parser printf
[petitboot] / discover / grub2 / script.c
index 0cf21967450efb3fbdf22c76f901c1c312b4d9d1..2aaf1d3d2cb1495a63c48fe7d31f72882d921b52 100644 (file)
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <log/log.h>
 #include <types/types.h>
 #include <talloc/talloc.h>
 
@@ -22,8 +23,8 @@
        container_of(stmt, struct grub2_statement_conditional, st)
 
 struct env_entry {
-       const char              *name;
-       const char              *value;
+       char                    *name;
+       char                    *value;
        struct list_item        list;
 };
 
@@ -34,6 +35,8 @@ struct grub2_symtab_entry {
        struct list_item        list;
 };
 
+static const char *default_prefix = "/boot/grub";
+
 static struct grub2_symtab_entry *script_lookup_function(
                struct grub2_script *script, const char *name)
 {
@@ -72,11 +75,13 @@ void script_env_set(struct grub2_script *script,
 
        if (!entry) {
                entry = talloc(script, struct env_entry);
-               entry->name = name;
+               entry->name = talloc_strdup(entry, name);
                list_add(&script->environment, &entry->list);
+       } else {
+               talloc_free(entry->value);
        }
 
-       entry->value = value;
+       entry->value = talloc_strdup(entry, value);
 }
 
 static bool expand_var(struct grub2_script *script, struct grub2_word *word)
@@ -278,7 +283,7 @@ int statement_simple_execute(struct grub2_script *script,
 
        entry = script_lookup_function(script, st->argv->argv[0]);
        if (!entry) {
-               fprintf(stderr, "undefined function '%s'\n", st->argv->argv[0]);
+               pb_log("grub2: undefined function '%s'\n", st->argv->argv[0]);
                return 1;
        }
 
@@ -400,7 +405,7 @@ static void init_env(struct grub2_script *script)
 
        env = talloc(script, struct env_entry);
        env->name = talloc_strdup(env, "prefix");
-       env->value = talloc_strdup(env, "/");
+       env->value = talloc_strdup(env, default_prefix);
 
        list_add(&script->environment, &env->list);
 }