From patchwork Thu Jan 21 18:44:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Heinrich Kiwi X-Patchwork-Id: 1430017 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 4DMBCP4Xh0z9rx8 for ; Fri, 22 Jan 2021 05:45:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=DivZIEMH; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4DMBCP3Qt5zDr7K for ; Fri, 22 Jan 2021 05:45:05 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=klaus@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=DivZIEMH; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4DMBC64chBzDqhn for ; Fri, 22 Jan 2021 05:44:50 +1100 (AEDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10LIWZ4A196122; Thu, 21 Jan 2021 13:44:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=D2p4WEkLuGho0UnH/TX3ZdD+nB7d/LmNz9An0QiLuRE=; b=DivZIEMHIaYuoeX2cjZ7PH7hNCAO8ZMhfBUmfONs7yCYuhgOwVRnS0/QbycibLDCLii9 P02L7GplqJB3i9HqXjwJ6FqF7c4VljiuuLoIk0FtVP5Dq0CA2wGuEQlWi18+Ab67+eAW zqAAY1yiZGd5MlKDhOKo1rC1hhusKX2POzc1LCnI3ZgbQ8OxA3Mc9zvqyK1Q3lczqdja QB1dDAqpgRKBWVBpPu55zKEFHIIJl97auGI8j8DLzFfT9cTuRfdp0Ip6Ar3bWJAsq7uT lW+UTDDuTCyFBjQVG9vBloE/4IPldt2cr5XruiGBOKb2fqgWPE+s6w4OA2HlCYqe4pXm Wg== Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 367eur8etp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Jan 2021 13:44:46 -0500 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 10LIEj7W005810; Thu, 21 Jan 2021 18:44:45 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma01wdc.us.ibm.com with ESMTP id 3668s7e48s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Jan 2021 18:44:45 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10LIiiAL13500772 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Jan 2021 18:44:44 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C45BBE04F; Thu, 21 Jan 2021 18:44:44 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8E382BE051; Thu, 21 Jan 2021 18:44:43 +0000 (GMT) Received: from klaus-virtual-ubuntu.aus.stglabs.ibm.com (unknown [9.80.239.98]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 21 Jan 2021 18:44:43 +0000 (GMT) From: Klaus Heinrich Kiwi To: petitboot@lists.ozlabs.org Subject: [PATCH v4 2/2] discover/grub2: Add the '-e' test support Date: Thu, 21 Jan 2021 15:44:37 -0300 Message-Id: <20210121184437.5613-2-klaus@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210121184437.5613-1-klaus@linux.vnet.ibm.com> References: <20210121184437.5613-1-klaus@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2021-01-21_09:2021-01-21, 2021-01-21 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 malwarescore=0 impostorscore=0 bulkscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101210093 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: , MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Grub2 allows a special-case of file test using the '-e' operator, where the path can be empty, and the device existance is tested. E.g.: if [ -e (md/md-boot) ]; then Add the support for testing this condition, as well as some tests for this scenario (also fix an existing testcase where this was wrongly passing). This fixes the following RH CoreOS bug: https://bugzilla.redhat.com/show_bug.cgi?id=1915540 Signed-off-by: Klaus Heinrich Kiwi --- discover/grub2/builtins.c | 7 +++++- test/parser/test-grub2-test-file-ops.c | 27 +++++++++++++++++++++++ test/parser/test-grub2-ubuntu-13_04-x86.c | 4 ++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index f32e8e5..ff28586 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -245,6 +245,11 @@ static bool builtin_test_op_file(struct grub2_script *script, char op, return false; switch (op) { + case 'e': + /* -e: for grub, a special case is testing for the device + * presence itself (e.g. allows null file). */ + result = true; + break; case 's': /* -s: return true if file exists and has non-zero size */ result = !path ? false : statbuf.st_size > 0; @@ -336,7 +341,7 @@ static bool builtin_test_op(struct grub2_script *script, return strlen(a1) != 0; } - if (!strcmp(op, "-s") || !strcmp(op, "-f")) { + if (!strcmp(op, "-s") || !strcmp(op, "-f") || !(strcmp(op, "-e"))) { *consumed = 2; return builtin_test_op_file(script, op[1], a1); } diff --git a/test/parser/test-grub2-test-file-ops.c b/test/parser/test-grub2-test-file-ops.c index 38214a1..94ee333 100644 --- a/test/parser/test-grub2-test-file-ops.c +++ b/test/parser/test-grub2-test-file-ops.c @@ -55,6 +55,28 @@ if [ ! -d / -a $status = success ] then status=fail_d_5 fi +if [ -e /file_that_does_not_exist -a $status = success ] +then status=fail_e_1 +fi +if [ ! -e /dir -a $status = success ] +then status=fail_e_2 +fi +if [ ! -e /empty_file -a $status = success ] +then status=fail_e_3 +fi +if [ -e "" -a $status = success ] +then status=fail_e_4 +fi +if [ ! -e / -a $status = success ] +then status=fail_e_5 +fi +if [ ! -e (00000000-0000-0000-0000-000000000001) -a $status = success ] +then status=fail_e_6 +fi +if [ -e (00000000-0000-0000-0000-000000000002) -a $status = success ] +then status=fail_e_7 +fi + menuentry $status { linux /vmlinux } @@ -64,9 +86,14 @@ void run_test(struct parser_test *test) { struct discover_boot_option *opt; struct discover_context *ctx; + struct discover_device *dev; ctx = test->ctx; + /* set local uuid */ + dev = test->ctx->device; + dev->uuid = "00000000-0000-0000-0000-000000000001"; + test_read_conf_embedded(test, "/grub2/grub.cfg"); test_add_dir(test, ctx->device, "/"); test_add_file_data(test, ctx->device, "/empty_file", "", 0); diff --git a/test/parser/test-grub2-ubuntu-13_04-x86.c b/test/parser/test-grub2-ubuntu-13_04-x86.c index 2f9aefd..785781a 100644 --- a/test/parser/test-grub2-ubuntu-13_04-x86.c +++ b/test/parser/test-grub2-ubuntu-13_04-x86.c @@ -19,13 +19,13 @@ void run_test(struct parser_test *test) check_unresolved_resource(opt->boot_image); check_unresolved_resource(opt->initrd); check_name(opt, "Kubuntu GNU/Linux"); - check_args(opt, "root=UUID=29beca39-9181-4780-bbb2-ab5d4be59aaf ro quiet splash "); + check_args(opt, "root=UUID=29beca39-9181-4780-bbb2-ab5d4be59aaf ro quiet splash vt.handoff=7"); opt = get_boot_option(ctx, 1); check_unresolved_resource(opt->boot_image); check_unresolved_resource(opt->initrd); check_name(opt, "Kubuntu GNU/Linux, with Linux 3.8.0-19-generic"); - check_args(opt, "root=UUID=29beca39-9181-4780-bbb2-ab5d4be59aaf ro quiet splash "); + check_args(opt, "root=UUID=29beca39-9181-4780-bbb2-ab5d4be59aaf ro quiet splash vt.handoff=7"); opt = get_boot_option(ctx, 2); check_name(opt, "Kubuntu GNU/Linux, with Linux 3.8.0-19-generic (recovery mode)");