]> git.ozlabs.org Git - petitboot/blobdiff - discover/boot.c
discover/grub2: Add var expansion code
[petitboot] / discover / boot.c
index 8ad83beb6a98673ecfea8844406da4c0f662078f..f52a91c1c8c18ee405bc0659c4d8847c1280ee99 100644 (file)
@@ -121,17 +121,23 @@ static int kexec_reboot(struct boot_task *task)
        return result;
 }
 
-static void update_status(boot_status_fn fn, void *arg, int type,
-               char *message)
+static void __attribute__((format(__printf__, 4, 5))) update_status(
+               boot_status_fn fn, void *arg, int type, char *fmt, ...)
 {
        struct boot_status status;
+       va_list ap;
+
+       va_start(ap, fmt);
+       status.message = talloc_vasprintf(NULL, fmt, ap);
+       va_end(ap);
 
        status.type = type;
-       status.message = message;
        status.progress = -1;
        status.detail = NULL;
 
        fn(arg, &status);
+
+       talloc_free(status.message);
 }
 
 static void boot_hook_update_param(void *ctx, struct boot_task *task,
@@ -279,18 +285,31 @@ int boot(void *ctx, struct discover_boot_option *opt, struct boot_command *cmd,
        unsigned int clean_image = 0;
        unsigned int clean_initrd = 0;
        unsigned int clean_dtb = 0;
+       const char *boot_desc;
        int result;
 
        image = NULL;
        initrd = NULL;
        dtb = NULL;
 
+       if (opt && opt->option->name)
+               boot_desc = opt->option->name;
+       else if (cmd && cmd->boot_image_file)
+               boot_desc = cmd->boot_image_file;
+       else
+               boot_desc = "(unknown)";
+
+       update_status(status_fn, status_arg, BOOT_STATUS_INFO,
+                       "Booting %s.", boot_desc);
+
        if (cmd && cmd->boot_image_file) {
                image = pb_url_parse(opt, cmd->boot_image_file);
        } else if (opt && opt->boot_image) {
                image = opt->boot_image->url;
        } else {
-               pb_log("%s: no image specified", __func__);
+               pb_log("%s: no image specified\n", __func__);
+               update_status(status_fn, status_arg, BOOT_STATUS_INFO,
+                               "Boot failed: no image specified");
                return -1;
        }
 
@@ -371,8 +390,6 @@ no_load:
        if (clean_dtb)
                unlink(boot_task->local_dtb);
 
-       talloc_free(boot_task);
-
        if (!result) {
                update_status(status_fn, status_arg, BOOT_STATUS_INFO,
                                "performing kexec reboot");
@@ -385,5 +402,7 @@ no_load:
                }
        }
 
+       talloc_free(boot_task);
+
        return result;
 }