]> git.ozlabs.org Git - petitboot/commitdiff
ui/ncurses: Keep track of the default boot option
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Thu, 28 Jun 2018 04:45:19 +0000 (14:45 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Mon, 3 Dec 2018 03:48:41 +0000 (14:48 +1100)
Keep track of the default boot option, and prefix its display name with
a '(*)' to point it out to the user.
This avoids having to authenticate with pb-discover even if only booting
the default option.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/device-handler.c
lib/pb-protocol/pb-protocol.c
lib/types/types.h
ui/ncurses/nc-cui.c

index e446cab528fb8d53238a6724a8deddb2dbc744a5..e75f41232db072e2db2a1aae4e6346b3574bdd99 100644 (file)
@@ -930,6 +930,10 @@ static void set_default(struct device_handler *handler,
                return;
        }
 
+       if (handler->default_boot_option)
+               handler->default_boot_option->option->is_autoboot_default = false;
+       opt->option->is_autoboot_default = true;
+
        handler->sec_to_boot = config_get()->autoboot_timeout_sec;
        handler->default_boot_option = opt;
        handler->default_boot_option_priority = new_prio;
index 5de382d2215bae22c216c1e3424a6147b308c7b2..d8771fcb9493296be9b879c1f841d4aa681a6273 100644 (file)
@@ -204,6 +204,7 @@ int pb_protocol_boot_option_len(const struct boot_option *opt)
                4 + optional_strlen(opt->boot_args) +
                4 + optional_strlen(opt->args_sig_file) +
                sizeof(opt->is_default) +
+               sizeof(opt->is_autoboot_default) +
                sizeof(opt->type);
 }
 
@@ -434,6 +435,8 @@ int pb_protocol_serialise_boot_option(const struct boot_option *opt,
 
        *(bool *)pos = opt->is_default;
        pos += sizeof(bool);
+       *(bool *)pos = opt->is_autoboot_default;
+       pos += sizeof(bool);
 
        *(uint32_t *)pos = __cpu_to_be32(opt->type);
        pos += 4;
@@ -925,6 +928,9 @@ int pb_protocol_deserialise_boot_option(struct boot_option *opt,
        opt->is_default = *(bool *)(pos);
        pos += sizeof(bool);
        len -= sizeof(bool);
+       opt->is_autoboot_default = *(bool *)(pos);
+       pos += sizeof(bool);
+       len -= sizeof(bool);
 
        if (read_u32(&pos, &len, &opt->type))
                return -1;
index f5392c89c4a7b1715622cf3d7520e956e24ac30b..39760d91848d150b9c01cc50bc609f77d2ceaf14 100644 (file)
@@ -54,6 +54,7 @@ struct boot_option {
        char            *boot_args;
        char            *args_sig_file;
        bool            is_default;
+       bool            is_autoboot_default;
 
        struct list_item        list;
 
index 495f78599b7b6ef3f72e061cf8e0e3c7f793814d..d80e2c3e5e6f0a30e48f11b1e623ea1ec26d7ac0 100644 (file)
@@ -392,11 +392,16 @@ static void cui_boot_cb(struct nc_scr *scr)
 
 static int cui_boot_check(struct pmenu_item *item)
 {
+       struct cui_opt_data *cod = cod_from_item(item);
        struct cui *cui = cui_from_item(item);
 
        if (discover_client_authenticated(cui->client))
                return cui_boot(item);
 
+       /* Client doesn't need authentication to boot the default option */
+       if (cui->default_item == cod->opt_hash)
+               return cui_boot(item);
+
        cui_show_auth(cui, item->pmenu->scr.main_ncw, false, cui_boot_cb);
 
        return 0;
@@ -932,8 +937,9 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
        dev_hdr = pmenu_find_device(menu, dev, opt);
 
        /* All actual boot entries are 'tabbed' across */
-       name = talloc_asprintf(menu, "%s%s",
-                       tab, opt->name ? : "Unknown Name");
+       name = talloc_asprintf(menu, "%s%s%s",
+                       tab, opt->is_autoboot_default ? "(*) " : "",
+                       opt->name ? : "Unknown Name");
 
        /* Save the item in opt->ui_info for cui_device_remove() */
        opt->ui_info = i = pmenu_item_create(menu, name);
@@ -1018,6 +1024,27 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
                        pb_log_fn("set_menu_items failed: %d\n", result);
        }
 
+       /* Update the default option */
+       if (opt->is_autoboot_default) {
+               struct cui_opt_data *tmp;
+               struct pmenu_item *item;
+               unsigned int j;
+               if (cui->default_item) {
+                       for (j = 0; j < cui->main->item_count; j++) {
+                               item = item_userptr(cui->main->items[j]);
+                               tmp = cod_from_item(item);
+                               if (tmp->opt_hash == cui->default_item) {
+                                       char *label =  talloc_asprintf(menu, "%s%s",
+                                                       tab, tmp->name ? : "Unknown Name");
+                                       pmenu_item_update(item, label);
+                                       talloc_free(label);
+                                       break;
+                               }
+                       }
+               }
+               cui->default_item = cod->opt_hash;
+       }
+
        /* Re-attach the items array. */
        result = set_menu_items(menu->ncm, menu->items);
 
@@ -1062,6 +1089,7 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
 static void cui_device_remove(struct device *dev, void *arg)
 {
        struct cui *cui = cui_from_arg(arg);
+       struct cui_opt_data *cod;
        struct boot_option *opt;
        unsigned int i;
        int rows, cols, top, last;
@@ -1084,6 +1112,9 @@ static void cui_device_remove(struct device *dev, void *arg)
 
        list_for_each_entry(&dev->boot_options, opt, list) {
                struct pmenu_item *item = pmenu_item_from_arg(opt->ui_info);
+               cod = cod_from_item(item);
+               if (cui->default_item == cod->opt_hash)
+                       cui->default_item = 0;
 
                assert(pb_protocol_device_cmp(dev, cod_from_item(item)->dev));
                if (opt->type == DISCOVER_PLUGIN_OPTION)