]> git.ozlabs.org Git - petitboot/blobdiff - discover/boot.c
discover/pxe-parser: Recognise plugin sources
[petitboot] / discover / boot.c
index d259de85964f09bc7786d84011be00520e9c0dab..fab4b61cd681d4a3aac00464641936029388e4e2 100644 (file)
@@ -34,17 +34,39 @@ enum {
        BOOT_HOOK_EXIT_UPDATE   = 2,
 };
 
+static void __attribute__((format(__printf__, 4, 5))) update_status(
+               boot_status_fn fn, void *arg, int type, char *fmt, ...)
+{
+       struct status status;
+       va_list ap;
+
+       va_start(ap, fmt);
+       status.message = talloc_vasprintf(NULL, fmt, ap);
+       va_end(ap);
+
+       status.type = type;
+       status.backlog = false;
+
+       pb_debug("boot status: [%d] %s\n", type, status.message);
+
+       fn(arg, &status);
+
+       talloc_free(status.message);
+}
+
 /**
  * kexec_load - kexec load helper.
  */
 static int kexec_load(struct boot_task *boot_task)
 {
-       int result;
-       const char *argv[7];
-       const char **p;
+       struct process *process;
        char *s_initrd = NULL;
-       char *s_dtb = NULL;
        char *s_args = NULL;
+       const char *argv[7];
+       char *s_dtb = NULL;
+       const char **p;
+       int result;
+
 
        boot_task->local_initrd_override = NULL;
        boot_task->local_dtb_override = NULL;
@@ -70,6 +92,17 @@ static int kexec_load(struct boot_task *boot_task)
        const char* local_image = (boot_task->local_image_override) ?
                boot_task->local_image_override : boot_task->local_image;
 
+       process = process_create(boot_task);
+       if (!process) {
+               pb_log("%s: failed to create process\n", __func__);
+               return -1;
+       }
+
+       process->path = pb_system_apps.kexec;
+       process->argv = argv;
+       process->keep_stdout = true;
+       process->add_stderr = true;
+
        p = argv;
        *p++ = pb_system_apps.kexec;    /* 1 */
        *p++ = "-l";                    /* 2 */
@@ -96,10 +129,19 @@ static int kexec_load(struct boot_task *boot_task)
        *p++ = local_image;             /* 6 */
        *p++ = NULL;                    /* 7 */
 
-       result = process_run_simple_argv(boot_task, argv);
+       result = process_run_sync(process);
+       if (result) {
+               pb_log("%s: failed to run process\n", __func__);
+               goto abort_kexec;
+       }
 
-       if (result)
+       result = process->exit_status;
+
+       if (result) {
                pb_log("%s: failed: (%d)\n", __func__, result);
+               update_status(boot_task->status_fn, boot_task->status_arg,
+                               STATUS_ERROR, "%s", process->stdout_buf);
+       }
 
 abort_kexec:
        gpg_validate_boot_files_cleanup(boot_task);
@@ -143,25 +185,6 @@ static int kexec_reboot(struct boot_task *task)
        return result;
 }
 
-static void __attribute__((format(__printf__, 4, 5))) update_status(
-               boot_status_fn fn, void *arg, int type, char *fmt, ...)
-{
-       struct status status;
-       va_list ap;
-
-       va_start(ap, fmt);
-       status.message = talloc_vasprintf(NULL, fmt, ap);
-       va_end(ap);
-
-       status.type = type;
-
-       pb_debug("boot status: [%d] %s\n", type, status.message);
-
-       fn(arg, &status);
-
-       talloc_free(status.message);
-}
-
 static void boot_hook_update_param(void *ctx, struct boot_task *task,
                const char *name, const char *value)
 {
@@ -309,12 +332,19 @@ static int check_load(struct boot_task *task, const char *name,
 {
        if (!result)
                return 0;
-       if (result->status != LOAD_ERROR)
+
+       if (result->status != LOAD_ERROR) {
+               update_status(task->status_fn, task->status_arg,
+                               STATUS_ERROR,
+                               _("Loaded %s from %s"), name,
+                               pb_url_to_string(result->url));
                return 0;
+       }
 
        update_status(task->status_fn, task->status_arg,
                        STATUS_ERROR,
-                       _("Couldn't load %s"), name);
+                       _("Couldn't load %s from %s"), name,
+                       pb_url_to_string(result->url));
        return -1;
 }
 
@@ -445,6 +475,7 @@ static void boot_process(struct load_url_result *result, void *data)
                        _("Performing kexec load"));
 
        rc = kexec_load(task);
+       pb_log("%s: kexec_load returned %d\n", __func__, rc);
        if (rc == KEXEC_LOAD_DECRYPTION_FALURE) {
                update_status(task->status_fn, task->status_arg,
                                STATUS_ERROR, _("Decryption failed"));
@@ -459,10 +490,6 @@ static void boot_process(struct load_url_result *result, void *data)
                                STATUS_ERROR,
                                _("Invalid signature configuration"));
        }
-       else if (rc) {
-               update_status(task->status_fn, task->status_arg,
-                               STATUS_ERROR, _("kexec load failed"));
-       }
 
 no_sig_load:
        cleanup_load(task->image_signature);
@@ -496,7 +523,8 @@ static int start_url_load(struct boot_task *task, const char *name,
        if (!url)
                return 0;
 
-       *result = load_url_async(task, url, boot_process, task);
+       *result = load_url_async(task, url, boot_process, task, NULL,
+                                task->status_arg);
        if (!*result) {
                update_status(task->status_fn, task->status_arg,
                                STATUS_ERROR, _("Error loading %s"), name);