From patchwork Thu Jun 20 16:09:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 1119572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45V6Rt6YqQz9s00 for ; Fri, 21 Jun 2019 02:18:02 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 45V6Rt5Dc2zDrGx for ; Fri, 21 Jun 2019 02:18:02 +1000 (AEST) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=209.85.128.68; helo=mail-wm1-f68.google.com; envelope-from=javierm@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45V6Rp6xj5zDr9w for ; Fri, 21 Jun 2019 02:17:58 +1000 (AEST) Received: by mail-wm1-f68.google.com with SMTP id a15so3653964wmj.5 for ; Thu, 20 Jun 2019 09:17:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t/upMHUw2pvsOC0ii1C+QS5sFgx9784eE9wR6SeC3L4=; b=WYCp7ctLIxd8NFzu09xITGsSp551YhARENSbbypwYQ5QyJARmloly/vDg994MHE//G PLhHOzQ+OMzC8zEv9Nci18qXS3gQ0SIbirUjn4LagPcifoDa9aU8bhV6QEf05MH8mRpN I6w15QXBwh5hyW+k3mNC9kCK82rYoWu523+bHlVeze7yVnCjyzmRjPE4qJm9rVSEuZbr wt+ywoRI/gRV8ZnH0ZHBNyw1Ykc3s93agV9W+JyqjJkRZOcM5XD5eNg11xiBRMbCw7PD X2+ZwmN6el0QEqNz8lEH0BVpLcpEn//86bWSNAeSGgrIA8q5mJACoCUEE3Vi9VXaBLIK pzbQ== X-Gm-Message-State: APjAAAVduC0hWbFHvHtpz1cNkgOVddC6BjVJhuhYTNLx54WoGnDTcotZ Jr0Sz0RFJohmKzw0aEa9YNd8Jqr438s= X-Google-Smtp-Source: APXvYqyO7b6lizNwKnrj1SEFw90z4N9HNgHLpE5EvwItSUPutu/sFItFKAPq+31jDpGPh9ad2SjAHw== X-Received: by 2002:a1c:6a11:: with SMTP id f17mr254728wmc.110.1561047009501; Thu, 20 Jun 2019 09:10:09 -0700 (PDT) Received: from minerva.redhat.com ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id h90sm78602wrh.15.2019.06.20.09.10.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 20 Jun 2019 09:10:08 -0700 (PDT) From: Javier Martinez Canillas To: petitboot@lists.ozlabs.org Subject: [PATCH 1/2] discover/grub2: Allow using title for default even if id was defined Date: Thu, 20 Jun 2019 18:09:55 +0200 Message-Id: <20190620160956.20651-2-javierm@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190620160956.20651-1-javierm@redhat.com> References: <20190620160956.20651-1-javierm@redhat.com> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas , Javier Martinez Canillas Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" A default menu entry can be chosen using any of the following attributes: index, title or id (if the entry was defined with the --id option). But Petitboot doesn't honor this correctly and only compares the default with the menu entry title if the entry doesn't have an id defined. This is wrong since an index or title can be used even if an id was defined. This issue wasn't covered by the test that sets a default using a title because the menu entries didn't have an id defined. Add an id to them. Signed-off-by: Javier Martinez Canillas --- discover/grub2/script.c | 8 +++----- test/parser/test-grub2-default-multiword.c | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/discover/grub2/script.c b/discover/grub2/script.c index 902df900459..c910bf8bc1a 100644 --- a/discover/grub2/script.c +++ b/discover/grub2/script.c @@ -117,12 +117,10 @@ static bool option_is_default(struct grub2_script *script, if (end != var && *end == '\0') return default_idx == script->n_options; - /* if we don't have an explicit id for this option, fall back to - * the name */ - if (!id) - id = opt->option->name; + if (id && !strcmp(id, var)) + return true; - return !strcmp(id, var); + return !strcmp(opt->option->name, var); } static void append_text_to_current_arg(struct grub2_argv *argv, diff --git a/test/parser/test-grub2-default-multiword.c b/test/parser/test-grub2-default-multiword.c index 25d1cf1e5f0..d455d622770 100644 --- a/test/parser/test-grub2-default-multiword.c +++ b/test/parser/test-grub2-default-multiword.c @@ -3,10 +3,10 @@ #if 0 /* PARSER_EMBEDDED_CONFIG */ set default="Multiple word option" -menuentry 'Non-defalt option' { +menuentry 'Non-defalt option' --id=option0 { linux /vmlinux.non-default } -menuentry 'Multiple word option' { +menuentry 'Multiple word option' --id=option1 { linux /vmlinux } #endif