Skip to contentSkip to conversation

Commands not executed in the else branch

DISCUSSION Pavel Roskin 2 participants 4 messages Apr 27, 2009 – May 3, 2009

lore
Share & tools
lore
#0 lore raw

Hello!

While testing the new "test" command, I have found that the "else" branch is not executed in some cases. "echo" and "set" are executed, but other commands are not. Even "hello" is not working. The problem is not specific to the "test" command. I can do it with "search" as well:

grub> if search -f /; then echo 0; else hello; fi
error: no such device
grub> if search -f /; then echo 0; else echo Hello World; fi Hello World
error: no such device
grub> if search -f /; then echo 0; else echo 1; hello; echo 2; fi 1
2
error: no such device
grub>

The problem disappears after there is a true condition in the "if" part.

Signature · 2 lines
Regards,
Pavel Roskin
#1 lore raw

Hi,

It's caused by the propagation of grub_errno value. This patch should fix it.

normal/execute.c +1 -0
index 8bf6d17..aec4589 100644
@@ -177,6 +177,7 @@ grub_script_execute_cmdif (struct grub_script_cmd *cmd)
      read from the env variable `?'.  */
   grub_script_execute_cmd (cmdif->exec_to_evaluate);
   result = grub_env_get ("?");
+  grub_errno = 0;
 
   /* Execute the `if' or the `else' part depending on the value of
      `?'.  */
Quoted 31 lines · Pavel Roskin

Hello!

While testing the new "test" command, I have found that the "else" branch is not executed in some cases.  "echo" and "set" are executed, but other commands are not.  Even "hello" is not working.  The problem is not specific to the "test" command.  I can do it with "search" as well:

grub> if search -f /; then echo 0; else hello; fi
error: no such device
grub> if search -f /; then echo 0; else echo Hello World; fi Hello World
error: no such device
grub> if search -f /; then echo 0; else echo 1; hello; echo 2; fi 1
2
error: no such device
grub>

The problem disappears after there is a true condition in the "if" part.

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 1 line
Bean
#2 lore raw

Quoting Bean <[email protected]>:

Quoted 9 lines

Hi,

It's caused by the propagation of grub_errno value. This patch should fix it.

normal/execute.c +0 -0
index 8bf6d17..aec4589 100644

normal/execute.c grub_script_execute_cmdif (struct grub_script_cmd *cmd) · line 183

Quoted 7 lines
normal/execute.c +1 -0
@@ -177,6 +177,7 @@ grub_script_execute_cmdif (struct grub_script_cmd *cmd)
      read from the env variable `?'.  */
   grub_script_execute_cmd (cmdif->exec_to_evaluate);
   result = grub_env_get ("?");
+  grub_errno = 0;
 
   /* Execute the `if' or the `else' part depending on the value of
      `?'.  */

Thanks, it's working fine!

Signature · 2 lines
Regards,
Pavel Roskin
#3 lore raw

Hi,

Committed.

Quoted 33 lines · Pavel Roskin

Quoting Bean <[email protected]>:

Quoted 16 lines

Hi,

It's caused by the propagation of grub_errno value. This patch should fix it.

normal/execute.c +0 -0
index 8bf6d17..aec4589 100644
@@ -177,6 +177,7 @@ grub_script_execute_cmdif (struct grub_script_cmd
 *cmd)

     read from the env variable `?'.  */ grub_script_execute_cmd (cmdif->exec_to_evaluate); result = grub_env_get ("?");
+  grub_errno = 0;

Quoted 2 lines

  /* Execute the if' or the else' part depending on the value of `?'.  */

Thanks, it's working fine!

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 1 line
Bean