From patchwork Fri Jan 15 01:08:48 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: 1426739 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 4DH33p20Gsz9sWQ for ; Fri, 15 Jan 2021 12:09:10 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linux.vnet.ibm.com 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=Bm1qU9EU; 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 4DH33p00D4zDsWx for ; Fri, 15 Jan 2021 12:09:10 +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; dmarc=pass (p=none dis=none) header.from=linux.vnet.ibm.com 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=Bm1qU9EU; 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 4DH33f1r5jzDsVs for ; Fri, 15 Jan 2021 12:09:00 +1100 (AEDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10F13Ii4079697 for ; Thu, 14 Jan 2021 20:08:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id; s=pp1; bh=PRPxRf8u6ycLj1+y5+5J3NPSGV4UfX0w+6+4Ud4f6Rk=; b=Bm1qU9EUpps0P/hRhughiMpPOodcGGKbOISoDU1nMZeElbCuoyIhQ/2CEkGb7f7u2/IE VicWY5cO0FQTxjSBPtgu8hF9tlCGfbF+bSV2+/B7ckGlEd9KMtUTXuUSG+4xnpm3AgPI zoNU9Gwr5IuZbGmOftIgC08XUFkA5hvQ5sZni4Ci9Z4ZPSy4cGTU4BTlz+78C5YZzSOY v2I06xpvgGWxGoSSVCGqXDRtBL0d4p7Slo4MFlswhOM+MxzPpITWntJRK6zD5b/qWJ62 DBIXFQaDWgVP1iCAy9EzB/tO5WQuQtQAy09zTahuFwCKK0xdKxnwcvY8gHS7rsYvyd+F eg== Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 3630urgcmx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Jan 2021 20:08:57 -0500 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 10F18AKC025261 for ; Fri, 15 Jan 2021 01:08:56 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma01dal.us.ibm.com with ESMTP id 35y449ugxt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 15 Jan 2021 01:08:56 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10F18twf27787764 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 01:08:55 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7FA5B78060; Fri, 15 Jan 2021 01:08:55 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 902857805F; Fri, 15 Jan 2021 01:08:54 +0000 (GMT) Received: from klaus-virtual-ubuntu.aus.stglabs.ibm.com (unknown [9.80.236.160]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 15 Jan 2021 01:08:54 +0000 (GMT) From: Klaus Heinrich Kiwi To: petitboot@lists.ozlabs.org Subject: [PATCH 1/2] discover: Allow for empty paths Date: Thu, 14 Jan 2021 22:08:48 -0300 Message-Id: <20210115010849.4102-1-klaus@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2021-01-14_10:2021-01-14, 2021-01-14 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 bulkscore=4 adultscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 malwarescore=0 lowpriorityscore=4 priorityscore=1501 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150003 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" Some grub tests involve a (device)/path structure, where it is actually legal to have an empty path. Adjust join_path() and dependant functions to allow for empty pathnames. Signed-off-by: Klaus Heinrich Kiwi --- discover/grub2/builtins.c | 8 ++++---- discover/grub2/grub2.c | 19 ++++++++++--------- discover/paths.c | 8 +++++--- test/parser/utils.c | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index ab1407a..31cbe0e 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -216,7 +216,7 @@ static int parse_to_device_path(struct grub2_script *script, return -1; *devp = dev; - *pathp = talloc_strdup(script, file->path); + *pathp = !file->path ? NULL : talloc_strdup(script, file->path); talloc_free(file); @@ -247,13 +247,13 @@ static bool builtin_test_op_file(struct grub2_script *script, char op, switch (op) { case 's': /* -s: return true if file exists and has non-zero size */ - result = statbuf.st_size > 0; + result = !path ? false : statbuf.st_size > 0; break; case 'f': /* -f: return true if file exists and is not a directory. This is * different than the behavior of "test", but is what GRUB does * (though note as above that we follow symlinks unlike GRUB). */ - result = !S_ISDIR(statbuf.st_mode); + result = !path ? false : !S_ISDIR(statbuf.st_mode); break; default: result = false; @@ -284,7 +284,7 @@ static bool builtin_test_op_dir(struct grub2_script *script, char op, if (rc) return false; - return S_ISDIR(statbuf.st_mode); + return !path ? false : S_ISDIR(statbuf.st_mode); } static bool builtin_test_op(struct grub2_script *script, diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c index b176ce2..52c75e9 100644 --- a/discover/grub2/grub2.c +++ b/discover/grub2/grub2.c @@ -118,7 +118,6 @@ struct grub2_file *grub2_parse_file(struct grub2_script *script, const char *str) { struct grub2_file *file; - size_t dev_len; char *pos; if (!str) @@ -129,6 +128,7 @@ struct grub2_file *grub2_parse_file(struct grub2_script *script, if (*str != '(') { /* just a path - no device, return path as-is */ file->path = talloc_strdup(file, str); + file->dev = NULL; } else { /* device plus path - split into components */ @@ -137,17 +137,18 @@ struct grub2_file *grub2_parse_file(struct grub2_script *script, /* no closing bracket, or zero-length path? */ if (!pos || *(pos+1) == '\0') { - talloc_free(file); - return NULL; + file->path = NULL; + } + else { + file->path = talloc_strdup(file, pos + 1); + file->dev = talloc_strndup(file, str + 1, (size_t) (pos - str - 1)); } - - file->path = talloc_strdup(file, pos + 1); - - dev_len = pos - str - 1; - if (dev_len) - file->dev = talloc_strndup(file, str + 1, dev_len); } + if (!file->dev && !file->path) { + talloc_free(file); + return NULL; + } return file; } diff --git a/discover/paths.c b/discover/paths.c index 16fdd59..3010ae3 100644 --- a/discover/paths.c +++ b/discover/paths.c @@ -55,9 +55,11 @@ char *join_paths(void *alloc_ctx, const char *a, const char *b) full_path = talloc_array(alloc_ctx, char, strlen(a) + strlen(b) + 2); strcpy(full_path, a); - if (b[0] != '/' && a[strlen(a) - 1] != '/') - strcat(full_path, "/"); - strcat(full_path, b); + if (strlen(b)) { + if (b[0] != '/' && a[strlen(a) - 1] != '/') + strcat(full_path, "/"); + strcat(full_path, b); + } return full_path; } diff --git a/test/parser/utils.c b/test/parser/utils.c index d8499a4..2705b9a 100644 --- a/test/parser/utils.c +++ b/test/parser/utils.c @@ -257,7 +257,7 @@ int parser_stat_path(struct discover_context *ctx, list_for_each_entry(&test->files, file, list) { if (file->dev != dev) continue; - if (strcmp(file->name, path)) + if (path && strcmp(file->name, path)) continue; statbuf->st_size = (off_t)file->size; From patchwork Fri Jan 15 01:08:49 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: 1426740 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DH3413Vlsz9sP7 for ; Fri, 15 Jan 2021 12:09:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linux.vnet.ibm.com 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=DZzjkynX; 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 4DH3412w6qzDsXJ for ; Fri, 15 Jan 2021 12:09:21 +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.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=klaus@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.vnet.ibm.com 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=DZzjkynX; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 4DH33r0vdnzDsWD for ; Fri, 15 Jan 2021 12:09:11 +1100 (AEDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10F123fF097240 for ; Thu, 14 Jan 2021 20:09:08 -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=emD0xB8YibMyzF12yw+GHqRLbLNnQgHqyn+siC2qbj4=; b=DZzjkynXHT59x7IxrfLtv7+w9mI4HzB9KZFPtPhyXPBy5+fLljVf0K9Rvs7Msihj7QaG RYIVXNHsIejEGORkLnrNKiREwUCZpRsHN7LYm5VRvP2bB647JLjV/bXSQGmTW8AbniC7 soAgGTg4JZMcv67hVVuf1I/CyQxrSQawcVonLBLe/09EplNxEtvYNkNJseJV3tKjffeF D6d94KiUxSkmDQcfc08rsyd4+gw4HsXuKxhjuhv3B22cA8TweJ1HgD0iNoFDAmcMxKWT ZFceN/ZnLmmZ2dX16QflFieuz/ecqi6gUuVIy5QT3lS1lp34ec4xpwbN0HSWBBRpGIwy 9A== Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0b-001b2d01.pphosted.com with ESMTP id 3630nygj5x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Jan 2021 20:09:06 -0500 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 10F187Kq012520 for ; Fri, 15 Jan 2021 01:09:06 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma03dal.us.ibm.com with ESMTP id 35y449uegt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 15 Jan 2021 01:09:06 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10F195CR14680446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 01:09:05 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E4ED878063; Fri, 15 Jan 2021 01:09:04 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 00CAC7805C; Fri, 15 Jan 2021 01:09:03 +0000 (GMT) Received: from klaus-virtual-ubuntu.aus.stglabs.ibm.com (unknown [9.80.236.160]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 15 Jan 2021 01:09:03 +0000 (GMT) From: Klaus Heinrich Kiwi To: petitboot@lists.ozlabs.org Subject: [PATCH 2/2] discover/grub2: Add the '-e' test support Date: Thu, 14 Jan 2021 22:08:49 -0300 Message-Id: <20210115010849.4102-2-klaus@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210115010849.4102-1-klaus@linux.vnet.ibm.com> References: <20210115010849.4102-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-14_10:2021-01-14, 2021-01-14 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 phishscore=0 adultscore=0 impostorscore=0 clxscore=1015 bulkscore=0 priorityscore=1501 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150001 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. 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 | 10 ++++++++-- test/parser/test-grub2-ubuntu-13_04-x86.c | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index 31cbe0e..0354b8a 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); } @@ -544,7 +549,8 @@ static struct { }; static const char *nops[] = { - "echo", "export", "insmod", "loadfont", "terminfo", + "echo", "export", "insmod", "loadfont", "terminfo", "serial", + "terminal_input", "terminal_output" }; void register_builtins(struct grub2_script *script) 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)");