[PATCH 2/2] discover/grub2: Add the '-e' test support
Klaus Heinrich Kiwi
klaus at linux.vnet.ibm.com
Fri Jan 15 12:08:49 AEDT 2021
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 at 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(-)
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)");
--
2.17.1
More information about the Petitboot
mailing list