discover/grub2: Implement 'search' command
authorJeremy Kerr <jk@ozlabs.org>
Mon, 16 Sep 2013 08:53:22 +0000 (16:53 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 24 Sep 2013 05:14:59 +0000 (13:14 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/grub2/builtins.c

index cd56dcc033f8eb67d414e68d241fd5e53b315edb..8171b8d4907bb2f2067f73ee790d6cb20fd74697 100644 (file)
@@ -97,6 +97,32 @@ static int builtin_initrd(struct grub2_script *script,
        return 0;
 }
 
        return 0;
 }
 
+static int builtin_search(struct grub2_script *script,
+               void *data __attribute__((unused)),
+               int argc, char *argv[])
+{
+       const char *env_var, *spec;
+       int i;
+
+       env_var = NULL;
+
+       for (i = 1; i < argc - 1; i++) {
+               if (!strncmp(argv[i], "--set=", strlen("--set="))) {
+                       env_var = argv[i] + strlen("--set=");
+                       break;
+               }
+       }
+
+       if (!env_var)
+               return 0;
+
+       spec = argv[argc - 1];
+
+       script_env_set(script, env_var, spec);
+
+       return 0;
+}
+
 static struct {
        const char *name;
        grub2_function fn;
 static struct {
        const char *name;
        grub2_function fn;
@@ -112,6 +138,10 @@ static struct {
        {
                .name = "initrd",
                .fn = builtin_initrd,
        {
                .name = "initrd",
                .fn = builtin_initrd,
+       },
+       {
+               .name = "search",
+               .fn = builtin_search,
        }
 };
 
        }
 };