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 From patchwork Thu Jun 20 16:09:56 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: 1119570 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45V6Pd3vFrz9s7h for ; Fri, 21 Jun 2019 02:16:05 +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 45V6Pb6fWfzDrGn for ; Fri, 21 Jun 2019 02:16:03 +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.221.66; helo=mail-wr1-f66.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-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) (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 45V6PR0R7zzDr9S for ; Fri, 21 Jun 2019 02:15:54 +1000 (AEST) Received: by mail-wr1-f66.google.com with SMTP id p11so3637350wre.7 for ; Thu, 20 Jun 2019 09:15:54 -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=jOIVPYFeOeZg/kk8e4nfBmixbkj/Qep8BCEWZ0S29kI=; b=m3WYog6xrndul7F81kCTunkLQk+4Du5eer9Q5yO2pk9GhSu1vsMAtNBPMCH0ZXWKts 3U6oTeH26qMQGdWYUGcKvEFd9R/T+Grc9TSYn+tg0POCv2d/Erp003+mPhIp3UT0PCn8 ndUpyZcr0l0OEcNuMMpiO9S3Q3fJaDxmsA0rRyDpjNYrmnXATtq58ayuqmcgkfSsecdq tCvV9iDLgcfYrN4GuiiblDG4e43A/4eqv0LENucJeW+uQcQ9sQieSztRdJ6tCgsCjXut a9HIpAejRY2hlYZnsl681SN5vSIV8AVVfIrMJYSR5a+bmI9+kX7gZkObOFsd+m2/svYl oMXw== X-Gm-Message-State: APjAAAXPGZpLR4kBcDNGPi3vIw/mar3aaPYKg6PvzUi/9tl0D0CzTU28 lyrw5/YEqTglaAP/2gG3zM7EAevurYo= X-Google-Smtp-Source: APXvYqyRmGPcHEVS9g3IEedUKNplt1kHZv+G2zJJdg/Ve5+8dtN1wdnfZVK4hVjxG5Rnc7XFxlvjBA== X-Received: by 2002:a5d:6549:: with SMTP id z9mr28756894wrv.63.1561047010935; Thu, 20 Jun 2019 09:10:10 -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.09 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 20 Jun 2019 09:10:10 -0700 (PDT) From: Javier Martinez Canillas To: petitboot@lists.ozlabs.org Subject: [PATCH 2/2] discover/grub2: Allow to separate the --id argument using a space char Date: Thu, 20 Jun 2019 18:09:56 +0200 Message-Id: <20190620160956.20651-3-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" The GRUB menuentry command allows to separate the arguments for options using either a '=' or a ' '. The latter is the convention used when the menu entries are defined in the GRUB config file, but this is currently not supported by Petitboot. Add tests to cover both using '--id=foo' and '--id foo' as options. Signed-off-by: Javier Martinez Canillas --- discover/grub2/script.c | 13 +++++++-- test/parser/Makefile.am | 2 ++ test/parser/test-grub2-default-id-space.c | 34 +++++++++++++++++++++++ test/parser/test-grub2-default-id.c | 34 +++++++++++++++++++++++ 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 test/parser/test-grub2-default-id-space.c create mode 100644 test/parser/test-grub2-default-id.c diff --git a/discover/grub2/script.c b/discover/grub2/script.c index c910bf8bc1a..8a9d91dac98 100644 --- a/discover/grub2/script.c +++ b/discover/grub2/script.c @@ -339,9 +339,16 @@ int statement_menuentry_execute(struct grub2_script *script, * implementation to get --id= working. */ for (i = 1; i < st->argv->argc; ++i) { - if (strncmp("--id=", st->argv->argv[i], 5) == 0) { - id = st->argv->argv[i] + 5; - break; + if (strncmp("--id", st->argv->argv[i], strlen("--id")) == 0) { + if (strlen(st->argv->argv[i]) > strlen("--id=")) { + id = st->argv->argv[i] + strlen("--id="); + break; + } + + if (i + 1 < st->argv->argc) { + id = st->argv->argv[i + 1]; + break; + } } } if (st->argv->argc > 0) diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index f9083bd6187..748c8366c24 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -19,6 +19,8 @@ parser_TESTS = \ test/parser/test-grub2-noeol \ test/parser/test-grub2-menuentry-formats \ test/parser/test-grub2-if-formats \ + test/parser/test-grub2-default-id \ + test/parser/test-grub2-default-id-space \ test/parser/test-grub2-default-index \ test/parser/test-grub2-default-multiword \ test/parser/test-grub2-implicit-default-unset \ diff --git a/test/parser/test-grub2-default-id-space.c b/test/parser/test-grub2-default-id-space.c new file mode 100644 index 00000000000..df0eb2af27b --- /dev/null +++ b/test/parser/test-grub2-default-id-space.c @@ -0,0 +1,34 @@ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ +set default=option1 +menuentry 'test-option-0' --id option0 { + linux /vmlinux.0 +} +menuentry 'test-option-1' --id option1 { + linux /vmlinux.1 +} +menuentry 'test-option-2' --id option2 { + linux /vmlinux.2 +} +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + test_read_conf_embedded(test, "/boot/grub2/grub.cfg"); + test_run_parser(test, "grub2"); + + ctx = test->ctx; + + check_boot_option_count(ctx, 3); + opt = get_boot_option(ctx, 1); + + check_name(opt, "test-option-1"); + check_resolved_local_resource(opt->boot_image, ctx->device, + "/vmlinux.1"); + check_is_default(opt); +} diff --git a/test/parser/test-grub2-default-id.c b/test/parser/test-grub2-default-id.c new file mode 100644 index 00000000000..a41a4f91457 --- /dev/null +++ b/test/parser/test-grub2-default-id.c @@ -0,0 +1,34 @@ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ +set default=option1 +menuentry 'test-option-0' --id=option0 { + linux /vmlinux.0 +} +menuentry 'test-option-1' --id=option1 { + linux /vmlinux.1 +} +menuentry 'test-option-2' --id=option2 { + linux /vmlinux.2 +} +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + test_read_conf_embedded(test, "/boot/grub2/grub.cfg"); + test_run_parser(test, "grub2"); + + ctx = test->ctx; + + check_boot_option_count(ctx, 3); + opt = get_boot_option(ctx, 1); + + check_name(opt, "test-option-1"); + check_resolved_local_resource(opt->boot_image, ctx->device, + "/vmlinux.1"); + check_is_default(opt); +}