+static char *autoboot_option_desc(void *ctx, const struct autoboot_option *opt)
+{
+ const char *type, *val;
+
+ if (opt->boot_type == BOOT_DEVICE_TYPE) {
+ type = _("device type");
+ val = device_type_display_name(opt->type);
+ } else if (opt->boot_type == BOOT_DEVICE_UUID) {
+ type = _("device UUID");
+ val = opt->uuid;
+ } else {
+ type = _("unknown specifier");
+ val = NULL;
+ }
+
+ return talloc_asprintf(ctx, "%s = %s", type, val);
+}
+
+void device_handler_apply_temp_autoboot(struct device_handler *handler,
+ struct autoboot_option *opt)
+{
+ unsigned int i;
+ char *desc;
+
+ handler->temp_autoboot = talloc_steal(handler, opt);
+
+ desc = autoboot_option_desc(handler, opt);
+ device_handler_status_info(handler,
+ _("Applying temporary autoboot override: %s"),
+ desc);
+ talloc_free(desc);
+
+ if (!handler->autoboot_enabled)
+ return;
+
+ if (!handler->default_boot_option)
+ return;
+
+ if (autoboot_option_matches(opt, handler->default_boot_option->device))
+ return;
+
+ /* cancel the default, and rescan available options */
+ device_handler_cancel_default(handler);
+
+ handler->autoboot_enabled = true;
+
+ for (i = 0; i < handler->n_devices; i++) {
+ struct discover_device *dev = handler->devices[i];
+ struct discover_boot_option *boot_opt;
+
+ if (!autoboot_option_matches(opt, dev))
+ continue;
+
+ list_for_each_entry(&dev->boot_options, boot_opt, list) {
+ if (boot_opt->option->is_default) {
+ set_default(handler, boot_opt);
+ break;
+ }
+ }
+ }
+}
+