diff mbox series

[2/2] discover/grub2: Add the '-e' test support

Message ID 20210115010849.4102-2-klaus@linux.vnet.ibm.com
State New
Headers show
Series [1/2] discover: Allow for empty paths | expand

Commit Message

Klaus Heinrich Kiwi Jan. 15, 2021, 1:08 a.m. UTC
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 <klaus@linux.vnet.ibm.com>
---
 discover/grub2/builtins.c                 | 10 ++++++++--
 test/parser/test-grub2-ubuntu-13_04-x86.c |  4 ++--
 2 files changed, 10 insertions(+), 4 deletions(-)

Comments

Klaus Heinrich Kiwi Jan. 15, 2021, 1:13 a.m. UTC | #1
On 1/14/2021 10:08 PM, Klaus Heinrich Kiwi wrote:

> @@ -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"
>   };

Just noted this slipped through.. will send a v2 for part 2 only..

  -K
diff mbox series

Patch

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)");