Currently, builtin commands take precedence over user-defined functions. This patch reverses that precedence, so that users can "override" builtin commands. Builtin commands may be accessed by issuing the command prefixed by an '@' character.
My motivation for this change is to hook insmod in loaded configfiles which set $prefix to a different location than desired. If there are any changes needed to help get this functionality included, please let me know. Glenn --- grub-core/script/execute.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index afd5513..0769151 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -941,14 +941,15 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) args = argv.args + 2; cmdname = argv.args[1]; } - grubcmd = grub_command_find (cmdname); - if (! grubcmd) + /* Allow user functions to override built in commands. */ + func = grub_script_function_find (cmdname); + if (! func) { grub_errno = GRUB_ERR_NONE; - /* It's not a GRUB command, try all functions. */ - func = grub_script_function_find (cmdname); - if (! func) + /* It's not a function, check if GRUB command. */ + grubcmd = grub_command_find ((cmdname[0] == '@')?(cmdname+1):cmdname); + if (! grubcmd) { /* As a last resort, try if it is an assignment. */ char *assign = grub_strdup (cmdname); @@ -977,7 +978,9 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) } /* Execute the GRUB command or function. */ - if (grubcmd) + if (func) + ret = grub_script_function_call (func, argc, args); + else { if (grub_extractor_level && !(grubcmd->flags & GRUB_COMMAND_FLAG_EXTRACTOR)) @@ -990,8 +993,6 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) else ret = (grubcmd->func) (grubcmd, argc, args); } - else - ret = grub_script_function_call (func, argc, args); if (invert) { -- 1.8.3.2 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel