X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=af9fbba3e0dfbd3803772659c1adca6e377375d3;hp=04a44848d4c452db00e7c9e80cda0b5c6274ac9e;hb=2312c424d516862877c45a9566816acfe2da0f06;hpb=9fbd73a208c9465b4bf9e2c80c7290b72e62ead1 diff --git a/discover/device-handler.c b/discover/device-handler.c index 04a4484..af9fbba 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -40,6 +40,9 @@ struct device_handler { struct discover_boot_option *default_boot_option; struct list unresolved_boot_options; + + struct boot_task *pending_boot; + bool pending_boot_is_default; }; static int mount_device(struct discover_device *dev); @@ -331,6 +334,9 @@ static int default_timeout(void *arg) if (!handler->default_boot_option) return 0; + if (handler->pending_boot) + return 0; + opt = handler->default_boot_option; if (handler->sec_to_boot) { @@ -346,8 +352,9 @@ static int default_timeout(void *arg) pb_log("Timeout expired, booting default option %s\n", opt->option->id); - boot(handler, handler->default_boot_option, NULL, - handler->dry_run, boot_status, handler); + handler->pending_boot = boot(handler, handler->default_boot_option, + NULL, handler->dry_run, boot_status, handler); + handler->pending_boot_is_default = true; return 0; } @@ -650,11 +657,16 @@ static struct discover_boot_option *find_boot_option_by_id( void device_handler_boot(struct device_handler *handler, struct boot_command *cmd) { - struct discover_boot_option *opt; + struct discover_boot_option *opt = NULL; - opt = find_boot_option_by_id(handler, cmd->option_id); + if (cmd->option_id && strlen(cmd->option_id)) + opt = find_boot_option_by_id(handler, cmd->option_id); - boot(handler, opt, cmd, handler->dry_run, boot_status, handler); + if (handler->pending_boot) + boot_cancel(handler->pending_boot); + handler->pending_boot = boot(handler, opt, cmd, handler->dry_run, + boot_status, handler); + handler->pending_boot_is_default = false; } void device_handler_cancel_default(struct device_handler *handler) @@ -673,6 +685,12 @@ void device_handler_cancel_default(struct device_handler *handler) pb_log("Cancelling default boot option\n"); + if (handler->pending_boot && handler->pending_boot_is_default) { + boot_cancel(handler->pending_boot); + handler->pending_boot = NULL; + handler->pending_boot_is_default = false; + } + handler->default_boot_option = NULL; status.type = BOOT_STATUS_INFO; @@ -803,11 +821,12 @@ static int umount_device(struct discover_device *dev) return -1; dev->mounted = false; - talloc_free(dev->mount_path); - dev->mount_path = NULL; pb_rmdir_recursive(mount_base(), dev->mount_path); + talloc_free(dev->mount_path); + dev->mount_path = NULL; + return 0; }