Skip to contentSkip to conversation

grub.cfg parser still doesn't abort on error

DISCUSSION Robert Millan 4 participants 10 messages Feb 2, 2008 – Feb 3, 2008

lore
Share & tools
lore
#0 lore raw

Try the following grub.cfg:

cat (memdisk)/non-existant-file
echo this point should never be reached
read

You'll see that the echo is reached, even if cat returned an error.

This becomes much worse when found in situations like:

font (xxx)/some-file.pff
terminal gfxterm

and the font wasn't loaded.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#1 lore raw
Quoted 6 lines · Robert Millan

Try the following grub.cfg:

cat (memdisk)/non-existant-file
echo this point should never be reached
read

Quoted 8 lines

You'll see that the echo is reached, even if cat returned an error.

This becomes much worse when found in situations like:

font (xxx)/some-file.pff
terminal gfxterm

and the font wasn't loaded.

Urgh! Bean committed a patch that zero'ed the error. Perhaps it was wrong? ;-)

Can you try reverting it? :-)

--
Marco

#2 lore raw
Quoted 15 lines · Marco Gerards
Quoted 13 lines · Robert Millan

Try the following grub.cfg:

cat (memdisk)/non-existant-file
echo this point should never be reached
read

You'll see that the echo is reached, even if cat returned an error.

This becomes much worse when found in situations like:

font (xxx)/some-file.pff
terminal gfxterm

Quoted 6 lines
Quoted 1 line

and the font wasn't loaded.

Urgh! Bean committed a patch that zero'ed the error. Perhaps it was wrong? ;-)

Can you try reverting it? :-)

Actually, it was wrong before that.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#3 lore raw
Quoted 16 lines · Robert Millan
Quoted 15 lines · Marco Gerards
Quoted 13 lines · Robert Millan

Try the following grub.cfg:

cat (memdisk)/non-existant-file
echo this point should never be reached
read

You'll see that the echo is reached, even if cat returned an error.

This becomes much worse when found in situations like:

font (xxx)/some-file.pff
terminal gfxterm

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

and the font wasn't loaded.

Urgh! Bean committed a patch that zero'ed the error. Perhaps it was wrong? ;-)

Can you try reverting it? :-)

Actually, it was wrong before that.

i think you can use the if statement to test command result.

Signature · 1 line
Bean
#4 lore raw
Quoted 15 lines · Bean
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

Try the following grub.cfg:

cat (memdisk)/non-existant-file
echo this point should never be reached
read

You'll see that the echo is reached, even if cat returned an error.

This becomes much worse when found in situations like:

font (xxx)/some-file.pff
terminal gfxterm

and the font wasn't loaded.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Urgh! Bean committed a patch that zero'ed the error. Perhaps it was wrong? ;-)

Can you try reverting it? :-)

Actually, it was wrong before that.

i think you can use the if statement to test command result.

You mean it is intentional? I think it's a bad plan to assume user will check for error status of each command, specially in situations like font/gfxterm.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#5 lore raw
Quoted 19 lines · Robert Millan
Quoted 18 lines · Bean
Quoted 18 lines
Quoted 18 lines
Quoted 6 lines

Try the following grub.cfg:

cat (memdisk)/non-existant-file
echo this point should never be reached
read

Quoted 8 lines

You'll see that the echo is reached, even if cat returned an error.

This becomes much worse when found in situations like:

font (xxx)/some-file.pff
terminal gfxterm

and the font wasn't loaded.

Urgh! Bean committed a patch that zero'ed the error. Perhaps it was wrong? ;-)

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Can you try reverting it? :-)

Actually, it was wrong before that.

i think you can use the if statement to test command result.

You mean it is intentional? I think it's a bad plan to assume user will check for error status of each command, specially in situations like font/gfxterm.

In fact, the most common error is the font command, as sometimes it can't find the font file from disk. I think you can change the grub.cfg to something like this:

if font (xxx)/some-file.pff ; then

  # graphic mode setting
else
  # text mode setting
fi

i think this behavior is consistent with sh, an error code returned from command should not cause the script to abort.

Signature · 1 line
Bean
#6 lore raw
Quoted 9 lines · Bean

if font (xxx)/some-file.pff ; then

  # graphic mode setting
else
  # text mode setting
fi

i think this behavior is consistent with sh, an error code returned from command should not cause the script to abort.

Urg, part of update-grub was written with the idea that this ought to be handled in "build" time. I guess I'll have to overhaul some of it...

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#7 lore raw
Quoted 8 lines · Robert Millan
Quoted 7 lines · Bean

if font (xxx)/some-file.pff ; then

  # graphic mode setting
else
  # text mode setting
fi
Quoted 5 lines
Quoted 2 lines

i think this behavior is consistent with sh, an error code returned from command should not cause the script to abort.

Urg, part of update-grub was written with the idea that this ought to be handled in "build" time. I guess I'll have to overhaul some of it...

Well, it wasn't such a big change after all. The sanity checks done at grub.cfg generation time are worth keeping, IMHO, since they off-load GRUB from performing them (and it is more practical to add logic in bash when possible).

This should address the problem.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)

* util/grub.d/00_header.in: Issue scripting commands for GRUB to only setup gfxterm when `font' command has succeeded.

util/grub.d/00_header.in renamed from grub2/util/grub.d/00_header.in +10 -9
diff -x CVS -x '*~' -x '*.mk' -urp ../grub2/util/grub.d/00_header.in ./util/grub.d/00_header.in
@@ -42,15 +42,14 @@ if [ "x${GRUB_DRIVE}" = "x" ] ; then : ;
   echo "set root=${GRUB_DRIVE}"
 fi
 
-if [ "x${GRUB_FONT_PATH}" = "x" ] ; then : ; else
-  echo "font ${GRUB_FONT_PATH}"
-fi
-
 case ${platform}:${GRUB_TERMINAL} in
   pc:gfxterm) cat << EOF
-set gfxmode=640x480
-insmod gfxterm
-insmod vbe
+if font ${GRUB_FONT_PATH} ; then
+  set gfxmode=640x480
+  insmod gfxterm
+  insmod vbe
+  terminal gfxterm
+fi
 EOF
   ;;
   *:serial)
@@ -59,7 +58,9 @@ EOF
       GRUB_SERIAL_COMMAND=serial
     fi
     echo "${GRUB_SERIAL_COMMAND}"
+    echo "terminal serial"
+  ;;
+  *:*)
+    echo "terminal ${GRUB_TERMINAL}"
   ;;
 esac
-
-echo "terminal ${GRUB_TERMINAL}"
#8 lore raw
Quoted 12 lines · Robert Millan
Quoted 11 lines · Robert Millan
Quoted 9 lines · Bean

if font (xxx)/some-file.pff ; then

  # graphic mode setting
else
  # text mode setting
fi

i think this behavior is consistent with sh, an error code returned from command should not cause the script to abort.

Quoted 8 lines
Quoted 2 lines

Urg, part of update-grub was written with the idea that this ought to be handled in "build" time. I guess I'll have to overhaul some of it...

Well, it wasn't such a big change after all. The sanity checks done at grub.cfg generation time are worth keeping, IMHO, since they off-load GRUB from performing them (and it is more practical to add logic in bash when possible).

This should address the problem.

Committed.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#9 lore raw
In reply to Robert Millan
Quoted 3 lines · Robert Millan

You mean it is intentional? I think it's a bad plan to assume user will check for error status of each command, specially in situations like font/gfxterm.

It is quite intentional. This behavior is consistent with Bash and GRUB Legacy. The concept is that the user still gets something, even if there is a small error. Since GRUB supports rewriting menu entries at runtime, this is generally a good thing.

Okuji