Misc bug fix for grub2
PATCH 1/1 Misc bug fix for grub2
Hi,
These small patches have been in my hd for quite some time, just post it together.
1, echo.mod missing in pkgdata_MODULES
2, Check for undefined variable, for example, if AA is not defined, echo $AA will output garbage, after this patch, echo $AA will output empty string.
3, Properly reset error number. In the following grub.cfg,
aaa
menuentry m1 {
set root=(hd0,1)
chainloader +1
}menuentry m2 {
set root=(hd0,2)
chainloader +1
}The menu will not be showed because the error caused by undefined command aaa will affect the parser. After the patch, the error number is reset and this problem wouldn't happen any more.
Signature · 1 line
Bean
2007-11-19 Bean <[email protected]>
* normal/execute.c (grub_script_exec_argument_to_string): Check for undefined variable. (grub_script_execute_cmdline): Reset grub_errno.
* normal/main.c (read_config_file): Reset grub_errno.
* conf/common.rmk (pkgdata_MODULES): Add echo.mod.
Index: normal/execute.c
===================================================================
RCS file: /sources/grub/grub2/normal/execute.c,v
retrieving revision 1.5
execute.c +10 -3
@@ -49,7 +49,8 @@ grub_script_execute_argument_to_string (if (argi->type ==1 ) { val =grub_env_get (argi->str); - size +=grub_strlen (val); +if (val) + size +=grub_strlen (val); }else size +=grub_strlen (argi->str);
@@ -67,7 +68,8 @@ grub_script_execute_argument_to_string (if (argi->type ==1 ) { val =grub_env_get (argi->str); -grub_strcat (chararg, val); +if (val) +grub_strcat (chararg, val); }else grub_strcat (chararg, argi->str);
@@ -99,6 +101,9 @@ grub_script_execute_cmdline (struct grub grubcmd =grub_command_find (cmdline->cmdname);if (! grubcmd) { +/* Ignore errors. */ + grub_errno =GRUB_ERR_NONE ; +/* It's not a GRUB command, try all functions. */ func =grub_script_function_find (cmdline->cmdname);if (! func)
@@ -118,7 +123,8 @@ grub_script_execute_cmdline (struct grub grub_errno =GRUB_ERR_NONE ; }grub_free (assign); -return 0 ; + ret = grub_errno; + goto quit; } }
@@ -167,6 +173,7 @@ grub_script_execute_cmdline (struct grubgrub_free (args[i]);grub_free (args); +quit:grub_sprintf (errnobuf,"%d" , ret);grub_env_set ("?" , errnobuf);
Index: normal/main.c
===================================================================
RCS file: /sources/grub/grub2/normal/main.c,v
retrieving revision 1.21
main.c +3 -0
@@ -261,6 +261,9 @@ read_config_file (const char *config, in/* Execute the command(s). */ grub_script_execute (parsed_script); +/* Ignore errors. */ + grub_errno =GRUB_ERR_NONE ; +/* The parsed script was executed, throw it away. */ grub_script_free (parsed_script); }
Index: conf/common.rmk
===================================================================
RCS file: /sources/grub/grub2/conf/common.rmk,v
retrieving revision 1.17
common.rmk +1 -1
@@ -197,7 +197,7 @@ lvm_mod_LDFLAGS = $(COMMON_LDFLAGS) # Commands. pkgdata_MODULES += hello.mod boot.mod terminal.mod ls.mod \ - cmp.mod cat.mod help.mod font.mod search.mod \ + echo.mod cmp.mod cat.mod help.mod font.mod search.mod \ loopback.mod configfile.mod \ terminfo.mod test.mod blocklist.mod hexdump.mod