From patchwork Wed Jan 31 21:49:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve McIntyre X-Patchwork-Id: 126417 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1127468ljc; Wed, 31 Jan 2018 13:50:54 -0800 (PST) X-Google-Smtp-Source: AH8x226KkWwuKdxA342cJi5SMMGFChBJabb42AaK3HbSaCDEWLfQ+G6ohbvaxxdA+pNuZUMoDvbg X-Received: by 10.37.128.197 with SMTP id c5mr22977846ybm.17.1517435454464; Wed, 31 Jan 2018 13:50:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517435454; cv=none; d=google.com; s=arc-20160816; b=HSd6Dh4Hgxv5FhZ5bJvd5hyexU7STO++rYGkMmJe1RTjADHhmO9YwnpD2exUje+xAN /HbMyW8VxMawWRjl/15Fq6QGJMwLved+W6D6Av5kHczQUfsRwEkrpy4xiWstLBe8gFzB UwXqye4LuhnMZmmmCN/wWGxukSHpEZye9EMyom6f+s/obwhyLuZFu/PiEI+fYdMYDhm7 1kI7cyJeaqRz8Bu2r9ne5psCLzrIRkrvnqTYYwPlas5O2uPgvtC73f6bVbfpVHALSFJb qloBzS+k78vt7Py+41vj5+iR8uAmXIJ09s4f+LYedFTzVIXjvElmJdLcDYl5U3DZJ6dk NY/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:arc-authentication-results; bh=rv2nXFVhQAQ45CNhrrpcqbN3DahvSYnyHLkBkKYYeIs=; b=odgd3GYyoTarEvPJis93gDEPFta1/OI8qFP+BMPv3y8vWxIqG0wFPwVObfC4hEm4DL DI8TZVM8MvSXJPA6a90TGOOCJXHE2LTkLS5xuf7ujtTPndyMK9qIagqzhEofHwf6BKBY WdvKlkGqiKC3Qrn6lmfXOYu2mFe0XWrJsR9oXIqcJbtvyzCVxsiIuGVN4T/aZDGyI9ti IGI75wolBFYWmPMeh84A/7gz6cWqP2cIgXk9Nwa4O06y0+s5OdmOMgpP/2+4jChulJFC YFHwz7OMo4n5JCSHVQBRD/g76ME5KbbbToTR84+XvzvSymRj++qzhb8WeeO7xXjkgAP6 UxMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t84si707447ywc.138.2018.01.31.13.50.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 31 Jan 2018 13:50:54 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org Received: from localhost ([::1]:33767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eh0HN-0005jr-UY for patch@linaro.org; Wed, 31 Jan 2018 16:50:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eh0Go-0005hY-Di for grub-devel@gnu.org; Wed, 31 Jan 2018 16:50:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eh0Gk-00036Q-EJ for grub-devel@gnu.org; Wed, 31 Jan 2018 16:50:18 -0500 Received: from cheddar.halon.org.uk ([93.93.131.118]:47238) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eh0Gk-00036E-71 for grub-devel@gnu.org; Wed, 31 Jan 2018 16:50:14 -0500 Received: from bsmtp by cheddar.halon.org.uk with local-bsmtp (Exim 4.89) (envelope-from ) id 1eh0Gg-0002xG-Sq; Wed, 31 Jan 2018 21:50:10 +0000 Received: from steve by tack.mossbank.org.uk with local (Exim 4.89) (envelope-from ) id 1eh0GL-0005JG-7n; Wed, 31 Jan 2018 21:49:49 +0000 From: Steve McIntyre To: Daniel Kiper , The development of GNU GRUB Subject: [PATCH] Make grub-install check for errors from efibootmgr Date: Wed, 31 Jan 2018 21:49:36 +0000 Message-Id: <20180131214936.19655-1-steve@einval.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180130174405.GA11729@router-fw-old.local.net-space.pl> References: <20180130174405.GA11729@router-fw-old.local.net-space.pl> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 93.93.131.118 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Steve McIntyre <93sam@debian.org>, Steve McIntyre MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" Code is currently ignoring errors from efibootmgr, giving users clearly bogus output like: Setting up grub-efi-amd64 (2.02~beta3-4) ... Installing for x86_64-efi platform. Could not delete variable: No space left on device Could not prepare Boot variable: No space left on device Installation finished. No error reported. and then potentially unbootable systems. If efibootmgr fails, grub-install should know that and report it! We've been using this patch in Debian now for some time, with no ill effects. Signed-off-by: Steve McIntyre <93sam@debian.org> --- grub-core/osdep/unix/platform.c | 24 +++++++++++++++--------- include/grub/util/install.h | 2 +- util/grub-install.c | 18 +++++++++++++----- 3 files changed, 29 insertions(+), 15 deletions(-) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c index a3fcfcaca..ca448bc11 100644 --- a/grub-core/osdep/unix/platform.c +++ b/grub-core/osdep/unix/platform.c @@ -78,19 +78,20 @@ get_ofpathname (const char *dev) dev); } -static void +static int grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) { int fd; pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd); char *line = NULL; size_t len = 0; + int rc; if (!pid) { grub_util_warn (_("Unable to open stream from %s: %s"), "efibootmgr", strerror (errno)); - return; + return errno; } FILE *fp = fdopen (fd, "r"); @@ -98,7 +99,7 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) { grub_util_warn (_("Unable to open stream from %s: %s"), "efibootmgr", strerror (errno)); - return; + return errno; } line = xmalloc (80); @@ -119,23 +120,25 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) bootnum = line + sizeof ("Boot") - 1; bootnum[4] = '\0'; if (!verbosity) - grub_util_exec ((const char * []){ "efibootmgr", "-q", + rc = grub_util_exec ((const char * []){ "efibootmgr", "-q", "-b", bootnum, "-B", NULL }); else - grub_util_exec ((const char * []){ "efibootmgr", + rc = grub_util_exec ((const char * []){ "efibootmgr", "-b", bootnum, "-B", NULL }); } free (line); + return rc; } -void +int grub_install_register_efi (grub_device_t efidir_grub_dev, const char *efifile_path, const char *efi_distributor) { const char * efidir_disk; int efidir_part; + int ret; efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk); efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1; @@ -151,23 +154,26 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL }); #endif /* Delete old entries from the same distributor. */ - grub_install_remove_efi_entries_by_distributor (efi_distributor); + ret = grub_install_remove_efi_entries_by_distributor (efi_distributor); + if (ret) + return ret; char *efidir_part_str = xasprintf ("%d", efidir_part); if (!verbosity) - grub_util_exec ((const char * []){ "efibootmgr", "-q", + ret = grub_util_exec ((const char * []){ "efibootmgr", "-q", "-c", "-d", efidir_disk, "-p", efidir_part_str, "-w", "-L", efi_distributor, "-l", efifile_path, NULL }); else - grub_util_exec ((const char * []){ "efibootmgr", + ret = grub_util_exec ((const char * []){ "efibootmgr", "-c", "-d", efidir_disk, "-p", efidir_part_str, "-w", "-L", efi_distributor, "-l", efifile_path, NULL }); free (efidir_part_str); + return ret; } void diff --git a/include/grub/util/install.h b/include/grub/util/install.h index 5910b0c09..0dba8b67f 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -210,7 +210,7 @@ grub_install_create_envblk_file (const char *name); const char * grub_install_get_default_x86_platform (void); -void +int grub_install_register_efi (grub_device_t efidir_grub_dev, const char *efifile_path, const char *efi_distributor); diff --git a/util/grub-install.c b/util/grub-install.c index 5e4cdfd2b..690f180c5 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -1848,9 +1848,13 @@ main (int argc, char *argv[]) if (!removable && update_nvram) { /* Try to make this image bootable using the EFI Boot Manager, if available. */ - grub_install_register_efi (efidir_grub_dev, - "\\System\\Library\\CoreServices", - efi_distributor); + int ret; + ret = grub_install_register_efi (efidir_grub_dev, + "\\System\\Library\\CoreServices", + efi_distributor); + if (ret) + grub_util_error (_("efibootmgr failed to register the boot entry: %s"), + strerror (ret)); } grub_device_close (ins_dev); @@ -1871,6 +1875,7 @@ main (int argc, char *argv[]) { char * efifile_path; char * part; + int ret; /* Try to make this image bootable using the EFI Boot Manager, if available. */ if (!efi_distributor || efi_distributor[0] == '\0') @@ -1887,8 +1892,11 @@ main (int argc, char *argv[]) efidir_grub_dev->disk->name, (part ? ",": ""), (part ? : "")); grub_free (part); - grub_install_register_efi (efidir_grub_dev, - efifile_path, efi_distributor); + ret = grub_install_register_efi (efidir_grub_dev, + efifile_path, efi_distributor); + if (ret) + grub_util_error (_("efibootmgr failed to register the boot entry: %s"), + strerror (ret)); } break;