[prev in list] [next in list] [prev in thread] [next in thread] 

List:       grub-devel
Subject:    Re: [PATCH] Allow user-defined functions to override builtins.
From:       Michel Hermier <michel.hermier () gmail ! com>
Date:       2014-05-19 9:38:13
Message-ID: 5379D105.7070904 () gmail ! com
[Download RAW message or body]

Le 19/05/2014 08:37, Glenn Washburn a écrit :
> 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.
If you want to go this way, I would have preferred a 'builtin' command 
like other shell do, instead of reinventing the wheel and invent a new 
syntax.
But this only my opinion as a user, wait for developers opinion.
>
> 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)
>       {


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic