From patchwork Mon Dec 19 04:19:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 706931 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3thnmK71gSz9s65 for ; Mon, 19 Dec 2016 15:21:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="HauPmoGu"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3thnmK5YsFzDwJF for ; Mon, 19 Dec 2016 15:21:21 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="HauPmoGu"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from mendozajonas.com (mendozajonas.com [188.166.185.233]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3thnkr0W4ZzDwBc for ; Mon, 19 Dec 2016 15:20:04 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="HauPmoGu"; dkim-atps=neutral Received: from skellige.ozlabs.ibm.com (unknown [122.99.82.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: sam@mendozajonas.com) by mendozajonas.com (Postfix) with ESMTPSA id A4AD4143FB0; Mon, 19 Dec 2016 12:20:00 +0800 (SGT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mendozajonas.com; s=mail; t=1482121201; bh=dq6o6Kyq7MKQSzwjPgHLj+6jDqdW47FQy1M8NASVJCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HauPmoGuifJXgimlYALsZgV+jMbST1fBV+5SJyZgYKCJpnzJKfmgbNfFkvixGZdZp DX27IRl+rqMqgjYCO8qlWdI15WJzTvuTuGHf3IUSzEP/WYmgb7cuJCFyGpAottOXZH USR+Hn3C4oY0eKGVV+wJnT+o481AkqZHgeCtwg/s= From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 22/29] discover/boot: Improve kexec error reporting Date: Mon, 19 Dec 2016 15:19:08 +1100 Message-Id: <20161219041915.30497-23-sam@mendozajonas.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161219041915.30497-1-sam@mendozajonas.com> References: <20161219041915.30497-1-sam@mendozajonas.com> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Update kexec_load() to preserve output from the call to `kexec -l`. On error retrieve the resulting error message and update the status line with it to provide a more informative error message. Signed-off-by: Samuel Mendoza-Jonas --- discover/boot.c | 77 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/discover/boot.c b/discover/boot.c index 82fba2f..5347fd7 100644 --- a/discover/boot.c +++ b/discover/boot.c @@ -34,17 +34,38 @@ 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; + + 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 +91,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 +128,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; + } + + result = process->exit_status; - if (result) + 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 +184,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) { @@ -452,6 +474,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")); @@ -466,10 +489,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);