diff options
Diffstat (limited to 'commands/boot.c')
-rw-r--r-- | commands/boot.c | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/commands/boot.c b/commands/boot.c index 0257b3dd4f..aeaba3992e 100644 --- a/commands/boot.c +++ b/commands/boot.c @@ -21,13 +21,29 @@ #include <linux/stat.h> +static char *next_argv(void *context) +{ + char ***argv = context; + char *next = **argv; + (*argv)++; + return next; +} + +static char *next_word(void *context) +{ + return strsep(context, " "); +} + static int do_boot(int argc, char *argv[]) { char *freep = NULL; int opt, ret = 0, do_list = 0, do_menu = 0; - int i, dryrun = 0, verbose = 0, timeout = -1; + int dryrun = 0, verbose = 0, timeout = -1; struct bootentries *entries; struct bootentry *entry; + void *handle; + const char *name; + char *(*next)(void *); while ((opt = getopt(argc, argv, "vldmt:w:")) > 0) { switch (opt) { @@ -54,31 +70,38 @@ static int do_boot(int argc, char *argv[]) } } - entries = bootentries_alloc(); - if (optind < argc) { - for (i = optind; i < argc; i++) { - ret = bootentry_create_from_name(entries, argv[i]); - if (ret <= 0) - printf("Nothing bootable found on '%s'\n", argv[i]); - } + handle = &argv[optind]; + next = next_argv; } else { const char *def; - char *sep, *name; def = getenv("global.boot.default"); if (!def) return 0; - sep = freep = xstrdup(def); + handle = freep = xstrdup(def); + next = next_word; + } + + entries = bootentries_alloc(); + + while ((name = next(&handle)) != NULL) { + ret = bootentry_create_from_name(entries, name); + if (ret <= 0) + printf("Nothing bootable found on '%s'\n", name); - while ((name = strsep(&sep, " ")) != NULL) { - ret = bootentry_create_from_name(entries, name); - if (ret <= 0) - printf("Nothing bootable found on '%s'\n", name); + if (do_list || do_menu) + continue; + + bootentries_for_each_entry(entries, entry) { + ret = boot_entry(entry, verbose, dryrun); + if (!ret) + break; } - free(freep); + bootentries_free(entries); + entries = bootentries_alloc(); } if (list_empty(&entries->entries)) { @@ -96,14 +119,9 @@ static int do_boot(int argc, char *argv[]) goto out; } - bootentries_for_each_entry(entries, entry) { - ret = boot_entry(entry, verbose, dryrun); - if (!ret) - break; - } - out: bootentries_free(entries); + free(freep); return ret; } |