All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michel Hermier <michel.hermier@gmail.com>
To: grub-devel@gnu.org
Subject: Re: [PATCH] Allow user-defined functions to override builtins.
Date: Mon, 19 May 2014 11:38:13 +0200	[thread overview]
Message-ID: <5379D105.7070904@gmail.com> (raw)
In-Reply-To: <20140519013715.1e36d215@crass-Ideapad-Z570>

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)
>       {



  reply	other threads:[~2014-05-19  9:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-19  6:37 [PATCH] Allow user-defined functions to override builtins Glenn Washburn
2014-05-19  9:38 ` Michel Hermier [this message]
2014-05-19 15:26   ` Ben Hildred
2014-05-22  7:31 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-05-24  7:47   ` Glenn Washburn
2014-05-25  3:03     ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-05-27  6:27       ` Glenn Washburn
2014-06-02 14:36         ` Andrey Borzenkov
2014-05-25  9:08   ` Michel Hermier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5379D105.7070904@gmail.com \
    --to=michel.hermier@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.