[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:       Ben Hildred <42656e () gmail ! com>
Date:       2014-05-19 15:26:03
Message-ID: CAKcyEGrWn3GqgA-==V6ajMzUreDTF0bBfa8PEyf6ot4ctUEt3Q () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Mon, May 19, 2014 at 3:38 AM, Michel Hermier <michel.hermier@gmail.com>wrote:

> 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.
>
> Seconded, particularly  as the @ syntax is used elsewhere as echo
suppression. there is no need to confuse people.

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



-- 
--
Ben Hildred
Automation Support Services
303 815 6721

[Attachment #5 (text/html)]

<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, \
May 19, 2014 at 3:38 AM, Michel Hermier <span dir="ltr">&lt;<a \
href="mailto:michel.hermier@gmail.com" \
target="_blank">michel.hermier@gmail.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Le 19/05/2014 08:37, Glenn Washburn a écrit :<div \
class=""><br> <blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"> Currently, builtin commands take \
precedence over user-defined<br> functions.   This patch reverses that precedence, so \
that users can<br> &quot;override&quot; builtin commands.   Builtin commands may be \
accessed by<br> issuing the command prefixed by an &#39;@&#39; character.<br>
</blockquote></div>
If you want to go this way, I would have preferred a &#39;builtin&#39; command like \
other shell do, instead of reinventing the wheel and invent a new syntax.<br> But \
this only my opinion as a user, wait for developers opinion.<div class="HOEnZb"><div \
class="h5"><br></div></div></blockquote><div>Seconded, particularly   as the @ syntax \
is used elsewhere as echo suppression. there is no need to confuse people.</div> \
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <br>
My motivation for this change is to hook insmod in loaded configfiles<br>
which set $prefix to a different location than desired.   If there are<br>
any changes needed to help get this functionality included, please let<br>
me know.<br>
<br>
Glenn<br>
<br>
---<br>
   grub-core/script/execute.c | 17 +++++++++--------<br>
   1 file changed, 9 insertions(+), 8 deletions(-)<br>
<br>
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c<br>
index afd5513..0769151 100644<br>
--- a/grub-core/script/execute.c<br>
+++ b/grub-core/script/execute.c<br>
@@ -941,14 +941,15 @@ grub_script_execute_cmdline (struct<br>
grub_script_cmd *cmd) args = argv.args + 2;<br>
            cmdname = argv.args[1];<br>
         }<br>
-   grubcmd = grub_command_find (cmdname);<br>
-   if (! grubcmd)<br>
+   /* Allow user functions to override built in commands. */<br>
+   func = grub_script_function_find (cmdname);<br>
+   if (! func)<br>
         {<br>
            grub_errno = GRUB_ERR_NONE;<br>
   -         /* It&#39;s not a GRUB command, try all functions.   */<br>
-         func = grub_script_function_find (cmdname);<br>
-         if (! func)<br>
+         /* It&#39;s not a function, check if GRUB command.   */<br>
+         grubcmd = grub_command_find ((cmdname[0] ==<br>
&#39;@&#39;)?(cmdname+1):cmdname);<br>
+         if (! grubcmd)<br>
            {<br>
               /* As a last resort, try if it is an assignment.   */<br>
               char *assign = grub_strdup (cmdname);<br>
@@ -977,7 +978,9 @@ grub_script_execute_cmdline (struct grub_script_cmd<br>
*cmd) }<br>
         /* Execute the GRUB command or function.   */<br>
-   if (grubcmd)<br>
+   if (func)<br>
+      ret = grub_script_function_call (func, argc, args);<br>
+   else<br>
         {<br>
            if (grub_extractor_level &amp;&amp; !(grubcmd-&gt;flags<br>
                                                      &amp; \
GRUB_COMMAND_FLAG_EXTRACTOR))<br> @@ -990,8 +993,6 @@ grub_script_execute_cmdline \
                (struct grub_script_cmd<br>
*cmd) else<br>
            ret = (grubcmd-&gt;func) (grubcmd, argc, args);<br>
         }<br>
-   else<br>
-      ret = grub_script_function_call (func, argc, args);<br>
         if (invert)<br>
         {<br>
</blockquote>
<br>
<br></div></div><div class="HOEnZb"><div class="h5">
______________________________<u></u>_________________<br>
Grub-devel mailing list<br>
<a href="mailto:Grub-devel@gnu.org" target="_blank">Grub-devel@gnu.org</a><br>
<a href="https://lists.gnu.org/mailman/listinfo/grub-devel" \
target="_blank">https://lists.gnu.org/mailman/<u></u>listinfo/grub-devel</a><br> \
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- \
<br><div>--</div><div><div>Ben Hildred</div><div>Automation Support \
Services</div></div><div>303 815 6721</div> </div></div>



_______________________________________________
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