+ return result && result->status == LOAD_ASYNC;
+}
+
+static int check_load(struct boot_task *task, const char *name,
+ struct load_url_result *result)
+{
+ if (!result)
+ return 0;
+
+ 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 from %s"), name,
+ pb_url_to_string(result->url));
+ return -1;
+}
+
+static void cleanup_load(struct load_url_result *result)
+{
+ if (!result)
+ return;
+ if (result->status != LOAD_OK)
+ return;
+ if (!result->cleanup_local)
+ return;
+ unlink(result->local);
+}
+
+static void cleanup_cancellations(struct boot_task *task,
+ struct load_url_result *cur_result)
+{
+ struct load_url_result *result, **results[] = {
+ &task->image, &task->initrd, &task->dtb,
+ };
+ bool pending = false;
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(results); i++) {
+ result = *results[i];
+
+ if (!result)
+ continue;
+
+ /* We need to cleanup and free any completed loads */
+ if (result == cur_result || result->status == LOAD_OK
+ || result->status == LOAD_ERROR) {
+ cleanup_load(result);
+ talloc_free(result);
+ *results[i] = NULL;
+
+ /* ... and cancel any pending loads, which we'll free in
+ * the completion callback */
+ } else if (result->status == LOAD_ASYNC) {
+ load_url_async_cancel(result);
+ pending = true;
+
+ /* if we're waiting for a cancellation, we still need to
+ * wait for the completion before freeing the boot task */
+ } else if (result->status == LOAD_CANCELLED) {
+ pending = true;
+ }
+ }
+
+ if (!pending)
+ talloc_free(task);
+}
+
+static void boot_process(struct load_url_result *result, void *data)
+{
+ struct boot_task *task = data;
+ int rc = -1;
+
+ if (task->cancelled) {
+ cleanup_cancellations(task, result);
+ return;
+ }
+
+ if (load_pending(task->image) ||
+ load_pending(task->initrd) ||
+ load_pending(task->dtb))
+ return;
+
+ if (check_load(task, "kernel image", task->image) ||
+ check_load(task, "initrd", task->initrd) ||
+ check_load(task, "dtb", task->dtb))
+ goto no_load;
+
+ if (task->verify_signature) {
+ if (load_pending(task->image_signature) ||
+ load_pending(task->initrd_signature) ||
+ load_pending(task->dtb_signature) ||
+ load_pending(task->cmdline_signature))
+ return;
+ }
+ if (task->decrypt_files) {
+ if (load_pending(task->cmdline_signature))
+ return;
+ }
+
+ if (task->verify_signature) {
+ if (check_load(task, "kernel image signature",
+ task->image_signature) ||
+ check_load(task, "initrd signature",
+ task->initrd_signature) ||
+ check_load(task, "dtb signature",
+ task->dtb_signature) ||
+ check_load(task, "command line signature",
+ task->cmdline_signature))
+ goto no_sig_load;
+ }
+ if (task->decrypt_files) {
+ if (load_pending(task->cmdline_signature))
+ return;
+
+ if (check_load(task, "command line signature",
+ task->cmdline_signature))
+ goto no_decrypt_sig_load;
+ }
+
+ /* we make a copy of the local paths, as the boot hooks might update
+ * and/or create these */
+ task->local_image = task->image ? task->image->local : NULL;
+ task->local_initrd = task->initrd ? task->initrd->local : NULL;
+ task->local_dtb = task->dtb ? task->dtb->local : NULL;
+
+ if (task->verify_signature) {
+ task->local_image_signature = task->image_signature ?
+ task->image_signature->local : NULL;
+ task->local_initrd_signature = task->initrd_signature ?
+ task->initrd_signature->local : NULL;
+ task->local_dtb_signature = task->dtb_signature ?
+ task->dtb_signature->local : NULL;
+ }
+ if (task->verify_signature || task->decrypt_files) {
+ task->local_cmdline_signature = task->cmdline_signature ?
+ task->cmdline_signature->local : NULL;
+ }
+
+ run_boot_hooks(task);