All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Obtaining the MAC address of the boot NIC for a PXE boot
       [not found] <1367240132.58582.YahooMailNeo@web120204.mail.ne1.yahoo.com>
@ 2013-05-01 14:59 ` Andrey Borzenkov
  2013-05-04 21:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-05-08 17:27   ` Obtaining the MAC address of the boot NIC for a PXE boot Rigoberto Corujo
  0 siblings, 2 replies; 21+ messages in thread
From: Andrey Borzenkov @ 2013-05-01 14:59 UTC (permalink / raw)
  To: Rigoberto Corujo; +Cc: help-grub, grub-devel

В Mon, 29 Apr 2013 05:55:32 -0700 (PDT)
Rigoberto Corujo <rcorujo@yahoo.com> пишет:

> Hello everyone,
> 
> With pxelinux, you can specify "IPAPPEND 2" in your boot loader configuration file and the MAC address of the boot NIC automatically gets appended to your kernel parameters as "BOOTIF=XX:XX:XX:XX:XX:XX". 
> 
> I am now trying to become familiar with Grub 2, because if its EFI support.   I noticed that with Grub 2, some of the documentation, which may be outdated, says that there is a "net_pxe_mac" variable which, as I understand it, should contain the MAC address of the boot NIC.  However, I've built the latest Grub 2 sources and, when I PXE boot and drop into a grub shell prompt, if type "set", I don't see "net_pxe_mac" listed as one of the variables.  I know there is a "net_ls_addr" command which prints out something like "efinet8 3c:4a:92:b2:6a:e8 10.1.1.114", but I don't know how to use Grub scripting to parse out the MAC address.  I also don't know if there will ever be a case where "net_ls_addr" will print out multiple entries on a PXE boot, making it difficult to determine which one corresponds to the boot NIC.
> 
> 
> Basically, I'm using the "ksdevice=bootif" kernel parameter when PXE booting my Red Hat kernel.  With PXE Linux, "bootif" provides the MAC address of the boot NIC.  I was hoping to do something like "ksdevice=${net_pxe_mac}", but since "net_pxe_mac" does not appear to be getting set, I need to find some other method.
> 


As it stands currently, net_pxe_* variables are defined on PC BIOS
platform only. For UEFI (which you apparently have) GRUB2 defines
net_efinetNN_* variables where efinetNN is symbolic name for interface
that was used to boot GRUB2.

May be GRUB2 should also define net_pxe_* namespace for the case of
UEFI. There is no real way to find out which interface was used for
booting and even if there were, grub does not support nested
variables substitution or eval'ing (like ${net_${boot_if}_mac).

Probably, adding "eval" support is really the most simple. Could you
test the patch below. What it does, is

- it adds "eval" command (same as known from UNIX shells) which
  executes its argument

- it exports boot interface as "efi_boot_interface" variable

This should allow you to do

if $grub_platform = efi ; then
  eval "set net_pxe_mac=\$net_${efi_boot_interface}_mac" 
fi

and then use $net_pxe_mac on both platforms.

If it works for you, I will clean it up; for consistency this is
probably needed for ieee1275 as well.

---
 grub-core/Makefile.core.def        |  5 ++++
 grub-core/commands/eval.c          | 51 ++++++++++++++++++++++++++++++++++++++
 grub-core/net/drivers/efi/efinet.c |  2 ++
 3 files changed, 58 insertions(+)

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 7e19acb..8844f2f 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -699,6 +699,11 @@ module = {
 };
 
 module = {
+  name = eval;
+  common = commands/eval.c;
+};
+
+module = {
   name = extcmd;
   common = commands/extcmd.c;
   common = lib/arg.c;
diff --git a/grub-core/commands/eval.c b/grub-core/commands/eval.c
new file mode 100644
index 0000000..a21ff89
--- /dev/null
+++ b/grub-core/commands/eval.c
@@ -0,0 +1,51 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/extcmd.h>
+#include <grub/i18n.h>
+#include <grub/term.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static grub_err_t
+grub_cmd_eval (grub_extcmd_context_t ctxt __attribute__((__unused__)),
+	       int argc, char *argv[])
+{
+  char *dummy[1] = { NULL };
+
+  if (argc != 1)
+    return  grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
+  return grub_script_execute_sourcecode (argv[0], 0, dummy);
+}
+
+static grub_extcmd_t cmd;
+
+GRUB_MOD_INIT(eval)
+{
+  cmd = grub_register_extcmd ("eval", grub_cmd_eval, 0,
+			      N_("[STRING]"), N_("Evaluate commands"),
+                              NULL);
+}
+
+GRUB_MOD_FINI(eval)
+{
+  grub_unregister_extcmd (cmd);
+}
+
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
index 2b344d6..f7d8fd5 100644
--- a/grub-core/net/drivers/efi/efinet.c
+++ b/grub-core/net/drivers/efi/efinet.c
@@ -23,6 +23,7 @@
 #include <grub/efi/api.h>
 #include <grub/efi/efi.h>
 #include <grub/i18n.h>
+#include <grub/env.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -250,6 +251,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
 				    &pxe_mode->dhcp_ack,
 				    sizeof (pxe_mode->dhcp_ack),
 				    1, device, path);
+    grub_env_set ("efi_boot_interface", card->name);
     return;
   }
 }
-- 
tg: (93daf86..) e/uefi_pxe_vars (depends on: master)



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: Obtaining the MAC address of the boot NIC for a PXE boot
  2013-05-01 14:59 ` Obtaining the MAC address of the boot NIC for a PXE boot Andrey Borzenkov
@ 2013-05-04 21:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-05-04 21:19     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-05-11 16:35     ` New command eval Andrey Borzenkov
  2013-05-08 17:27   ` Obtaining the MAC address of the boot NIC for a PXE boot Rigoberto Corujo
  1 sibling, 2 replies; 21+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-05-04 21:08 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 2233 bytes --]


> As it stands currently, net_pxe_* variables are defined on PC BIOS
> platform only. For UEFI (which you apparently have) GRUB2 defines
> net_efinetNN_* variables where efinetNN is symbolic name for interface
> that was used to boot GRUB2.
> 
> May be GRUB2 should also define net_pxe_* namespace for the case of
> UEFI.


"pxe" is the name of drivers used for BIOS. But it's ok to define
net_boot_* on all platforms and make it alias to the boot interface.

	> There is no real way to find out which interface was used for
> booting and even if there were, grub does not support nested
> variables substitution or eval'ing (like ${net_${boot_if}_mac).
> 

Bash doesn't support such construction either. We generally prefer to
stay reasonably close to bash to allow for easy reference and testing.

> Probably, adding "eval" support is really the most simple. Could you
> test the patch below. What it does, is
> 
> - it adds "eval" command (same as known from UNIX shells) which
>   executes its argument

eval is generally good

> 
> - it exports boot interface as "efi_boot_interface" variable
> 

This is needlessly EFI-specific. Similar variable would be useful on
many platforms. But a possible problem is that it's not known when using
native drivers (and on some platforms you have to). Perhaps making
something similar to "root" partition would be useful:
E.g.
net_default_interface=pxe
echo $net_default_mac
With net_default_interface defined to boot one on boot.
This would parallel net_default_server.

> This should allow you to do
> 
> if $grub_platform = efi ; then
>   eval "set net_pxe_mac=\$net_${efi_boot_interface}_mac" 
> fi
> 

Defining system variables manually looks dirty.

> +static grub_err_t
> +grub_cmd_eval (grub_extcmd_context_t ctxt __attribute__((__unused__)),
> +	       int argc, char *argv[])
> +{

You don't use any argument parsing. It's better to use command and not
extcmd in this case. Also "eval" in bash concatenates its arguments.

> +  cmd = grub_register_extcmd ("eval", grub_cmd_eval, 0,
> +			      N_("[STRING]"), N_("Evaluate commands"),

This description seems a bit vague for either human-reading or translation.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Obtaining the MAC address of the boot NIC for a PXE boot
  2013-05-04 21:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-05-04 21:19     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-05-05  5:17       ` Andrey Borzenkov
  2013-05-11 16:35     ` New command eval Andrey Borzenkov
  1 sibling, 1 reply; 21+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-05-04 21:19 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 3038 bytes --]

Patch for net_default_*. Please test.

=== modified file 'grub-core/net/bootp.c'
--- grub-core/net/bootp.c	2013-01-20 13:24:47 +0000
+++ grub-core/net/bootp.c	2013-05-04 21:16:02 +0000
@@ -211,6 +211,9 @@
       grub_print_error ();
     }
 
+  if (is_def)
+    grub_env_set ("net_default_interface", name);
+
   if (device && !*device && bp->server_ip)
     {
       *device = grub_xasprintf ("tftp,%d.%d.%d.%d",

=== modified file 'grub-core/net/net.c'
--- grub-core/net/net.c	2013-01-21 01:33:46 +0000
+++ grub-core/net/net.c	2013-05-04 21:13:29 +0000
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2010,2011  Free Software Foundation, Inc.
+ *  Copyright (C) 2010,2011,2012,2013  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -813,6 +813,65 @@
   return grub_net_default_server ? : "";
 }
 
+static const char *
+defip_get_env (struct grub_env_var *var __attribute__ ((unused)),
+	       const char *val)
+{
+  const char *intf = grub_env_get ("net_default_interface");
+  const char *ret = NULL;
+  if (intf)
+    {
+      char *buf = grub_xasprintf ("net_%s_ip", intf);
+      ret = grub_env_get (buf);
+      grub_free (buf);
+    }
+  return ret;
+}
+
+static char *
+defip_set_env (struct grub_env_var *var __attribute__ ((unused)),
+	       const char *val)
+{
+  const char *intf = grub_env_get ("net_default_interface");
+  if (intf)
+    {
+      char *buf = grub_xasprintf ("net_%s_ip", intf);
+      grub_env_set (buf, val);
+      grub_free (buf);
+    }
+  return NULL;
+}
+
+
+static const char *
+defmac_get_env (struct grub_env_var *var __attribute__ ((unused)),
+	       const char *val)
+{
+  const char *intf = grub_env_get ("net_default_interface");
+  const char *ret = NULL;
+  if (intf)
+    {
+      char *buf = grub_xasprintf ("net_%s_mac", intf);
+      ret = grub_env_get (buf);
+      grub_free (buf);
+    }
+  return ret;
+}
+
+static char *
+defmac_set_env (struct grub_env_var *var __attribute__ ((unused)),
+	       const char *val)
+{
+  const char *intf = grub_env_get ("net_default_interface");
+  if (intf)
+    {
+      char *buf = grub_xasprintf ("net_%s_mac", intf);
+      grub_env_set (buf, val);
+      grub_free (buf);
+    }
+  return NULL;
+}
+
 
 static void
 grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter)
@@ -1560,6 +1619,10 @@
 			       defserver_set_env);
   grub_register_variable_hook ("pxe_default_server", defserver_get_env,
 			       defserver_set_env);
+  grub_register_variable_hook ("net_default_ip", defip_get_env,
+			       defip_set_env);
+  grub_register_variable_hook ("net_default_mac", defmac_get_env,
+			       defmac_set_env);
 
   cmd_addaddr = grub_register_command ("net_add_addr", grub_cmd_addaddr,
 					/* TRANSLATORS: HWADDRESS stands for



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Obtaining the MAC address of the boot NIC for a PXE boot
  2013-05-04 21:19     ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-05-05  5:17       ` Andrey Borzenkov
  2013-05-07 10:03         ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 21+ messages in thread
From: Andrey Borzenkov @ 2013-05-05  5:17 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 3408 bytes --]

В Sat, 04 May 2013 23:19:50 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> Patch for net_default_*. Please test.
> 
> === modified file 'grub-core/net/bootp.c'
> --- grub-core/net/bootp.c	2013-01-20 13:24:47 +0000
> +++ grub-core/net/bootp.c	2013-05-04 21:16:02 +0000
> @@ -211,6 +211,9 @@
>        grub_print_error ();
>      }
>  
> +  if (is_def)
> +    grub_env_set ("net_default_interface", name);
> +
>    if (device && !*device && bp->server_ip)
>      {
>        *device = grub_xasprintf ("tftp,%d.%d.%d.%d",
> 
> === modified file 'grub-core/net/net.c'
> --- grub-core/net/net.c	2013-01-21 01:33:46 +0000
> +++ grub-core/net/net.c	2013-05-04 21:13:29 +0000
> @@ -1,6 +1,6 @@
>  /*
>   *  GRUB  --  GRand Unified Bootloader
> - *  Copyright (C) 2010,2011  Free Software Foundation, Inc.
> + *  Copyright (C) 2010,2011,2012,2013  Free Software Foundation, Inc.
>   *
>   *  GRUB is free software: you can redistribute it and/or modify
>   *  it under the terms of the GNU General Public License as published by
> @@ -813,6 +813,65 @@
>    return grub_net_default_server ? : "";
>  }
>  
> +static const char *
> +defip_get_env (struct grub_env_var *var __attribute__ ((unused)),
> +	       const char *val)
> +{
> +  const char *intf = grub_env_get ("net_default_interface");
> +  const char *ret = NULL;
> +  if (intf)
> +    {
> +      char *buf = grub_xasprintf ("net_%s_ip", intf);
> +      ret = grub_env_get (buf);

This will crash if grub_xasprintf fails.

> +      grub_free (buf);
> +    }
> +  return ret;
> +}
> +
> +static char *
> +defip_set_env (struct grub_env_var *var __attribute__ ((unused)),
> +	       const char *val)
> +{
> +  const char *intf = grub_env_get ("net_default_interface");
> +  if (intf)
> +    {
> +      char *buf = grub_xasprintf ("net_%s_ip", intf);
> +      grub_env_set (buf, val);
> +      grub_free (buf);
> +    }
> +  return NULL;
> +}
> +
> +
> +static const char *
> +defmac_get_env (struct grub_env_var *var __attribute__ ((unused)),
> +	       const char *val)
> +{
> +  const char *intf = grub_env_get ("net_default_interface");
> +  const char *ret = NULL;
> +  if (intf)
> +    {
> +      char *buf = grub_xasprintf ("net_%s_mac", intf);
> +      ret = grub_env_get (buf);
> +      grub_free (buf);
> +    }
> +  return ret;
> +}
> +
> +static char *
> +defmac_set_env (struct grub_env_var *var __attribute__ ((unused)),
> +	       const char *val)
> +{
> +  const char *intf = grub_env_get ("net_default_interface");
> +  if (intf)
> +    {
> +      char *buf = grub_xasprintf ("net_%s_mac", intf);
> +      grub_env_set (buf, val);
> +      grub_free (buf);
> +    }
> +  return NULL;
> +}
> +
>  
>  static void
>  grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter)
> @@ -1560,6 +1619,10 @@
>  			       defserver_set_env);
>    grub_register_variable_hook ("pxe_default_server", defserver_get_env,
>  			       defserver_set_env);
> +  grub_register_variable_hook ("net_default_ip", defip_get_env,
> +			       defip_set_env);
> +  grub_register_variable_hook ("net_default_mac", defmac_get_env,
> +			       defmac_set_env);
>  
>    cmd_addaddr = grub_register_command ("net_add_addr", grub_cmd_addaddr,
>  					/* TRANSLATORS: HWADDRESS stands for
> 
> 


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Obtaining the MAC address of the boot NIC for a PXE boot
  2013-05-05  5:17       ` Andrey Borzenkov
@ 2013-05-07 10:03         ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-05-07 17:50           ` Documentation for (Re: Obtaining the MAC address of the boot NIC for a PXE boot) Andrey Borzenkov
  0 siblings, 1 reply; 21+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-05-07 10:03 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 3884 bytes --]

On 05.05.2013 07:17, Andrey Borzenkov wrote:

> В Sat, 04 May 2013 23:19:50 +0200
> Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
> 
>> Patch for net_default_*. Please test.
>>
>> === modified file 'grub-core/net/bootp.c'
>> --- grub-core/net/bootp.c	2013-01-20 13:24:47 +0000
>> +++ grub-core/net/bootp.c	2013-05-04 21:16:02 +0000
>> @@ -211,6 +211,9 @@
>>        grub_print_error ();
>>      }
>>  
>> +  if (is_def)
>> +    grub_env_set ("net_default_interface", name);
>> +
>>    if (device && !*device && bp->server_ip)
>>      {
>>        *device = grub_xasprintf ("tftp,%d.%d.%d.%d",
>>
>> === modified file 'grub-core/net/net.c'
>> --- grub-core/net/net.c	2013-01-21 01:33:46 +0000
>> +++ grub-core/net/net.c	2013-05-04 21:13:29 +0000
>> @@ -1,6 +1,6 @@
>>  /*
>>   *  GRUB  --  GRand Unified Bootloader
>> - *  Copyright (C) 2010,2011  Free Software Foundation, Inc.
>> + *  Copyright (C) 2010,2011,2012,2013  Free Software Foundation, Inc.
>>   *
>>   *  GRUB is free software: you can redistribute it and/or modify
>>   *  it under the terms of the GNU General Public License as published by
>> @@ -813,6 +813,65 @@
>>    return grub_net_default_server ? : "";
>>  }
>>  
>> +static const char *
>> +defip_get_env (struct grub_env_var *var __attribute__ ((unused)),
>> +	       const char *val)
>> +{
>> +  const char *intf = grub_env_get ("net_default_interface");
>> +  const char *ret = NULL;
>> +  if (intf)
>> +    {
>> +      char *buf = grub_xasprintf ("net_%s_ip", intf);
>> +      ret = grub_env_get (buf);
> 
> This will crash if grub_xasprintf fails.
> 

Right, thanks. This patch was actually meant to just show the principle.
Fixed this and another problem with it, tested and now comitting.

>> +      grub_free (buf);
>> +    }
>> +  return ret;
>> +}
>> +
>> +static char *
>> +defip_set_env (struct grub_env_var *var __attribute__ ((unused)),
>> +	       const char *val)
>> +{
>> +  const char *intf = grub_env_get ("net_default_interface");
>> +  if (intf)
>> +    {
>> +      char *buf = grub_xasprintf ("net_%s_ip", intf);
>> +      grub_env_set (buf, val);
>> +      grub_free (buf);
>> +    }
>> +  return NULL;
>> +}
>> +
>> +
>> +static const char *
>> +defmac_get_env (struct grub_env_var *var __attribute__ ((unused)),
>> +	       const char *val)
>> +{
>> +  const char *intf = grub_env_get ("net_default_interface");
>> +  const char *ret = NULL;
>> +  if (intf)
>> +    {
>> +      char *buf = grub_xasprintf ("net_%s_mac", intf);
>> +      ret = grub_env_get (buf);
>> +      grub_free (buf);
>> +    }
>> +  return ret;
>> +}
>> +
>> +static char *
>> +defmac_set_env (struct grub_env_var *var __attribute__ ((unused)),
>> +	       const char *val)
>> +{
>> +  const char *intf = grub_env_get ("net_default_interface");
>> +  if (intf)
>> +    {
>> +      char *buf = grub_xasprintf ("net_%s_mac", intf);
>> +      grub_env_set (buf, val);
>> +      grub_free (buf);
>> +    }
>> +  return NULL;
>> +}
>> +
>>  
>>  static void
>>  grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter)
>> @@ -1560,6 +1619,10 @@
>>  			       defserver_set_env);
>>    grub_register_variable_hook ("pxe_default_server", defserver_get_env,
>>  			       defserver_set_env);
>> +  grub_register_variable_hook ("net_default_ip", defip_get_env,
>> +			       defip_set_env);
>> +  grub_register_variable_hook ("net_default_mac", defmac_get_env,
>> +			       defmac_set_env);
>>  
>>    cmd_addaddr = grub_register_command ("net_add_addr", grub_cmd_addaddr,
>>  					/* TRANSLATORS: HWADDRESS stands for
>>
>>
> 
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Documentation for (Re: Obtaining the MAC address of the boot NIC for a PXE boot)
  2013-05-07 10:03         ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-05-07 17:50           ` Andrey Borzenkov
  2013-05-07 19:45             ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 21+ messages in thread
From: Andrey Borzenkov @ 2013-05-07 17:50 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 5740 bytes --]

В Tue, 07 May 2013 12:03:51 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> Fixed this and another problem with it, tested and now comitting.
> 

Below documentation for new variables. It also changes variables
description to indicate that they contain variable interface name (do
we need to list possible values?). OK to commit?

From: Andrey Borzenkov <arvidjaar@gmail.com>
To: grub-devel@gnu.org
Subject: [PATCH] document new net_default_(interface|ip|mac) variables

Also generalize description to indicate that other variables may apply
to more than pxe interface.

Signed-off-by: Andrey Borzenkov <arvidjaar@gmail.com>

---
 docs/grub.texi | 111 +++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 76 insertions(+), 35 deletions(-)

diff --git a/docs/grub.texi b/docs/grub.texi
index bfd42ee..79bbcb0 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -2134,36 +2134,49 @@ this should be changed both in the prefix and in any references to the
 device name in the configuration file.
 
 GRUB provides several environment variables which may be used to inspect or
-change the behaviour of the PXE device:
+change the behaviour of the PXE device. In the following description
+@var{<interface>} is placeholder for the name of network interface (platform
+dependent):
 
 @table @samp
-@item net_pxe_ip
-The IP address of this machine.  Read-only.
+@item net_@var{<interface>}_ip
+The network interface's IP address.  Read-only.
 
-@item net_pxe_mac
+@item net_@var{<interface>}_mac
 The network interface's MAC address.  Read-only.
 
-@item net_pxe_hostname
+@item net_@var{<interface>}_hostname
 The client host name provided by DHCP.  Read-only.
 
-@item net_pxe_domain
+@item net_@var{<interface>}_domain
 The client domain name provided by DHCP.  Read-only.
 
-@item net_pxe_rootpath
+@item net_@var{<interface>}_rootpath
 The path to the client's root disk provided by DHCP.  Read-only.
 
-@item net_pxe_extensionspath
+@item net_@var{<interface>}_extensionspath
 The path to additional DHCP vendor extensions provided by DHCP.  Read-only.
 
-@item net_pxe_boot_file
+@item net_@var{<interface>}_boot_file
 The boot file name provided by DHCP.  Read-only.
 
-@item net_pxe_dhcp_server_name
+@item net_@var{<interface>}_dhcp_server_name
 The name of the DHCP server responsible for these boot parameters.
 Read-only.
 
+@item net_default_interface
+The name of interface that was used to load grub.  Read-only.
+
+@item net_default_ip
+The IP address of default interface. Read-only. This is alias for the
+@samp{net_$@{net_default_interface@}_ip}.
+
+@item net_default_mac
+The default interface's MAC address.  Read-only.  This is alias for the
+@samp{net_$@{net_default_interface@}_mac}.
+
 @item net_default_server
-The default server.  Read-write, although setting this is only useful
+The default TFTP server.  Read-write, although setting this is only useful
 before opening a network device.
 
 @end table
@@ -2735,14 +2748,18 @@ These variables have special meaning to GRUB.
 * locale_dir::
 * menu_color_highlight::
 * menu_color_normal::
-* net_pxe_boot_file::
-* net_pxe_dhcp_server_name::
-* net_pxe_domain::
-* net_pxe_extensionspath::
-* net_pxe_hostname::
-* net_pxe_ip::
-* net_pxe_mac::
-* net_pxe_rootpath::
+* net_@var{<interface>}_boot_file::
+* net_@var{<interface>}_dhcp_server_name::
+* net_@var{<interface>}_domain::
+* net_@var{<interface>}_extensionspath::
+* net_@var{<interface>}_hostname::
+* net_@var{<interface>}_ip::
+* net_@var{<interface>}_mac::
+* net_@var{<interface>}_rootpath::
+* net_default_interface::
+* net_default_ip::
+* net_default_mac::
+* net_default_server::
 * pager::
 * prefix::
 * pxe_blksize::
@@ -3009,50 +3026,74 @@ variable changes those colors.  For the available color names,
 The default is the value of @samp{color_normal} (@pxref{color_normal}).
 
 
-@node net_pxe_boot_file
-@subsection net_pxe_boot_file
+@node net_@var{<interface>}_boot_file
+@subsection net_@var{<interface>}_boot_file
+
+@xref{Network}.
+
+
+@node net_@var{<interface>}_dhcp_server_name
+@subsection net_@var{<interface>}_dhcp_server_name
+
+@xref{Network}.
+
+
+@node net_@var{<interface>}_domain
+@subsection net_@var{<interface>}_domain
+
+@xref{Network}.
+
+
+@node net_@var{<interface>}_extensionspath
+@subsection net_@var{<interface>}_extensionspath
+
+@xref{Network}.
+
+
+@node net_@var{<interface>}_hostname
+@subsection net_@var{<interface>}_hostname
 
 @xref{Network}.
 
 
-@node net_pxe_dhcp_server_name
-@subsection net_pxe_dhcp_server_name
+@node net_@var{<interface>}_ip
+@subsection net_@var{<interface>}_ip
 
 @xref{Network}.
 
 
-@node net_pxe_domain
-@subsection net_pxe_domain
+@node net_@var{<interface>}_mac
+@subsection net_@var{<interface>}_mac
 
 @xref{Network}.
 
 
-@node net_pxe_extensionspath
-@subsection net_pxe_extensionspath
+@node net_@var{<interface>}_rootpath
+@subsection net_@var{<interface>}_rootpath
 
 @xref{Network}.
 
 
-@node net_pxe_hostname
-@subsection net_pxe_hostname
+@node net_default_interface
+@subsection net_default_interface
 
 @xref{Network}.
 
 
-@node net_pxe_ip
-@subsection net_pxe_ip
+@node net_default_ip
+@subsection net_default_ip
 
 @xref{Network}.
 
 
-@node net_pxe_mac
-@subsection net_pxe_mac
+@node net_default_mac
+@subsection net_default_mac
 
 @xref{Network}.
 
 
-@node net_pxe_rootpath
-@subsection net_pxe_rootpath
+@node net_default_server
+@subsection net_default_server
 
 @xref{Network}.
 
-- 
tg: (48f959f..) u/default_interface (depends on: master)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: Documentation for (Re: Obtaining the MAC address of the boot NIC for a PXE boot)
  2013-05-07 17:50           ` Documentation for (Re: Obtaining the MAC address of the boot NIC for a PXE boot) Andrey Borzenkov
@ 2013-05-07 19:45             ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-05-08 14:52               ` Andrey Borzenkov
  0 siblings, 1 reply; 21+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-05-07 19:45 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 617 bytes --]


> +@item net_default_interface
> +The name of interface that was used to load grub.  Read-only.
> +

It's read-write. Also its value doesn't influence anything other than
net_default_* variables. The real card is determined from routing table
and server.

>  @item net_default_server
> -The default server.  Read-write, although setting this is only useful
> +The default TFTP server.  Read-write, although setting this is only useful
>  before opening a network device.

It's not restricted to tftp. You can do e.g. cat (http)/boot/grub/grub.cfg
Other than these 2 problems patch is ok to commit.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Documentation for (Re: Obtaining the MAC address of the boot NIC for a PXE boot)
  2013-05-07 19:45             ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-05-08 14:52               ` Andrey Borzenkov
  0 siblings, 0 replies; 21+ messages in thread
From: Andrey Borzenkov @ 2013-05-08 14:52 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 812 bytes --]

В Tue, 07 May 2013 21:45:14 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> 
> > +@item net_default_interface
> > +The name of interface that was used to load grub.  Read-only.
> > +
> 
> It's read-write. Also its value doesn't influence anything other than
> net_default_* variables.

Added clarification.

> 
> >  @item net_default_server
> > -The default server.  Read-write, although setting this is only useful
> > +The default TFTP server.  Read-write, although setting this is only useful
> >  before opening a network device.
> 
> It's not restricted to tftp. You can do e.g. cat (http)/boot/grub/grub.cfg

OK, reverted and reference to Device syntax section

> Other than these 2 problems patch is ok to commit.
> 

pushed with above changes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Obtaining the MAC address of the boot NIC for a PXE boot
  2013-05-01 14:59 ` Obtaining the MAC address of the boot NIC for a PXE boot Andrey Borzenkov
  2013-05-04 21:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-05-08 17:27   ` Rigoberto Corujo
  2013-05-08 19:25     ` Andrey Borzenkov
  1 sibling, 1 reply; 21+ messages in thread
From: Rigoberto Corujo @ 2013-05-08 17:27 UTC (permalink / raw)
  To: Andrey Borzenkov; +Cc: help-grub, grub-devel

----- Original Message -----

> From: Andrey Borzenkov <arvidjaar@gmail.com>
> To: Rigoberto Corujo <rcorujo@yahoo.com>
> Cc: "help-grub@gnu.org" <help-grub@gnu.org>; grub-devel@gnu.org
> Sent: Wednesday, May 1, 2013 10:59 AM
> Subject: Re: Obtaining the MAC address of the boot NIC for a PXE boot
> 
> В Mon, 29 Apr 2013 05:55:32 -0700 (PDT)
> Rigoberto Corujo <rcorujo@yahoo.com> пишет:
> 
>>  Hello everyone,
>> 
>>  With pxelinux, you can specify "IPAPPEND 2" in your boot loader 
> configuration file and the MAC address of the boot NIC automatically gets 
> appended to your kernel parameters as "BOOTIF=XX:XX:XX:XX:XX:XX". 
>> 
>>  I am now trying to become familiar with Grub 2, because if its EFI support. 
>   I noticed that with Grub 2, some of the documentation, which may be outdated, 
> says that there is a "net_pxe_mac" variable which, as I understand it, 
> should contain the MAC address of the boot NIC.  However, I've built the 
> latest Grub 2 sources and, when I PXE boot and drop into a grub shell prompt, if 
> type "set", I don't see "net_pxe_mac" listed as one of 
> the variables.  I know there is a "net_ls_addr" command which prints 
> out something like "efinet8 3c:4a:92:b2:6a:e8 10.1.1.114", but I 
> don't know how to use Grub scripting to parse out the MAC address.  I also 
> don't know if there will ever be a case where "net_ls_addr" will 
> print out multiple entries on a PXE boot, making it difficult to determine which 
> one corresponds to the boot NIC.
>> 
>> 
>>  Basically, I'm using the "ksdevice=bootif" kernel parameter 
> when PXE booting my Red Hat kernel.  With PXE Linux, "bootif" provides 
> the MAC address of the boot NIC.  I was hoping to do something like 
> "ksdevice=${net_pxe_mac}", but since "net_pxe_mac" does not 
> appear to be getting set, I need to find some other method.
>> 
> 
> 
> As it stands currently, net_pxe_* variables are defined on PC BIOS
> platform only. For UEFI (which you apparently have) GRUB2 defines
> net_efinetNN_* variables where efinetNN is symbolic name for interface
> that was used to boot GRUB2.
> 
> May be GRUB2 should also define net_pxe_* namespace for the case of
> UEFI. There is no real way to find out which interface was used for
> booting and even if there were, grub does not support nested
> variables substitution or eval'ing (like ${net_${boot_if}_mac).
> 
> Probably, adding "eval" support is really the most simple. Could you
> test the patch below. What it does, is
> 
> - it adds "eval" command (same as known from UNIX shells) which
>   executes its argument
> 
> - it exports boot interface as "efi_boot_interface" variable
> 
> This should allow you to do
> 
> if $grub_platform = efi ; then
>   eval "set net_pxe_mac=\$net_${efi_boot_interface}_mac" 
> fi
> 
> and then use $net_pxe_mac on both platforms.
> 
> If it works for you, I will clean it up; for consistency this is
> probably needed for ieee1275 as well.
> 
> ---
> grub-core/Makefile.core.def        |  5 ++++
> grub-core/commands/eval.c          | 51 ++++++++++++++++++++++++++++++++++++++
> grub-core/net/drivers/efi/efinet.c |  2 ++
> 3 files changed, 58 insertions(+)
> 
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index 7e19acb..8844f2f 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -699,6 +699,11 @@ module = {
> };
> 
> module = {
> +  name = eval;
> +  common = commands/eval.c;
> +};
> +
> +module = {
>    name = extcmd;
>    common = commands/extcmd.c;
>    common = lib/arg.c;
> diff --git a/grub-core/commands/eval.c b/grub-core/commands/eval.c
> new file mode 100644
> index 0000000..a21ff89
> --- /dev/null
> +++ b/grub-core/commands/eval.c
> @@ -0,0 +1,51 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2009  Free Software Foundation, Inc.
> + *
> + *  GRUB is free software: you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation, either version 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <grub/dl.h>
> +#include <grub/misc.h>
> +#include <grub/extcmd.h>
> +#include <grub/i18n.h>
> +#include <grub/term.h>
> +
> +GRUB_MOD_LICENSE ("GPLv3+");
> +
> +static grub_err_t
> +grub_cmd_eval (grub_extcmd_context_t ctxt __attribute__((__unused__)),
> +           int argc, char *argv[])
> +{
> +  char *dummy[1] = { NULL };
> +
> +  if (argc != 1)
> +    return  grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument 
> expected"));
> +  return grub_script_execute_sourcecode (argv[0], 0, dummy);
> +}
> +
> +static grub_extcmd_t cmd;
> +
> +GRUB_MOD_INIT(eval)
> +{
> +  cmd = grub_register_extcmd ("eval", grub_cmd_eval, 0,
> +                  N_("[STRING]"), N_("Evaluate commands"),
> +                              NULL);
> +}
> +
> +GRUB_MOD_FINI(eval)
> +{
> +  grub_unregister_extcmd (cmd);
> +}
> +
> diff --git a/grub-core/net/drivers/efi/efinet.c 
> b/grub-core/net/drivers/efi/efinet.c
> index 2b344d6..f7d8fd5 100644
> --- a/grub-core/net/drivers/efi/efinet.c
> +++ b/grub-core/net/drivers/efi/efinet.c
> @@ -23,6 +23,7 @@
> #include <grub/efi/api.h>
> #include <grub/efi/efi.h>
> #include <grub/i18n.h>
> +#include <grub/env.h>
> 
> GRUB_MOD_LICENSE ("GPLv3+");
> 
> @@ -250,6 +251,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char 
> **device,
>                     &pxe_mode->dhcp_ack,
>                     sizeof (pxe_mode->dhcp_ack),
>                     1, device, path);
> +    grub_env_set ("efi_boot_interface", card->name);
>      return;
>    }
> }
> -- 
> tg: (93daf86..) e/uefi_pxe_vars (depends on: master)
> 
> 
> _______________________________________________
> Help-grub mailing list
> Help-grub@gnu.org
> https://lists.gnu.org/mailman/listinfo/help-grub
> 

Thank you very much, Andrey.  This worked.  I did have to add the following lines to "grub-core/Makefile.core.am" to get a "eval.mod" generated, but I'm sure that it's probably because I missed an important step that would have automatically generated it.


if COND_x86_64_efi
platform_PROGRAMS += eval.module
MODULE_FILES += eval.module$(EXEEXT)
eval_module_SOURCES  = commands/eval.c  ## platform sources
nodist_eval_module_SOURCES  =  ## platform nodist sources
eval_module_LDADD  =
eval_module_CFLAGS  = $(AM_CFLAGS) $(CFLAGS_MODULE)
eval_module_LDFLAGS  = $(AM_LDFLAGS) $(LDFLAGS_MODULE)
eval_module_CPPFLAGS  = $(AM_CPPFLAGS) $(CPPFLAGS_MODULE)
eval_module_CCASFLAGS  = $(AM_CCASFLAGS) $(CCASFLAGS_MODULE)
EXTRA_DIST +=
BUILT_SOURCES += $(nodist_eval_module_SOURCES)
CLEANFILES += $(nodist_eval_module_SOURCES)
MOD_FILES += eval.mod
MARKER_FILES += eval.marker
CLEANFILES += eval.marker

eval.marker: $(eval_module_SOURCES) $(nodist_eval_module_SOURCES)
        $(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(eval_module_CPPFLAGS) $(CPPFLAGS) $^ > $@.new || (rm -f $@; exit 1)
        grep 'MARKER' $@.new > $@; rm -f $@.new
endif

Anyway, thank you once again.

Rigoberto



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Obtaining the MAC address of the boot NIC for a PXE boot
  2013-05-08 17:27   ` Obtaining the MAC address of the boot NIC for a PXE boot Rigoberto Corujo
@ 2013-05-08 19:25     ` Andrey Borzenkov
  2013-05-10 16:12       ` Rigoberto Corujo
  0 siblings, 1 reply; 21+ messages in thread
From: Andrey Borzenkov @ 2013-05-08 19:25 UTC (permalink / raw)
  To: Rigoberto Corujo; +Cc: help-grub, grub-devel

В Wed, 8 May 2013 10:27:47 -0700 (PDT)
Rigoberto Corujo <rcorujo@yahoo.com> пишет:

> 
> Thank you very much, Andrey.  This worked.  I did have to add the following lines to "grub-core/Makefile.core.am" to get a "eval.mod" generated, but I'm sure that it's probably because I missed an important step that would have automatically generated it.
> 

In the meantime Vladimir pushed different implementation that provides
net_default_mac:

`net_default_interface'
     Initially set to name of network interface that was used to load
     grub.  Read-write, although setting it affects only interpretation
     of `net_default_ip' and `net_default_mac'

`net_default_ip'
     The IP address of default interface.  Read-only. This is alias for
     the `net_${net_default_interface}_ip'.

`net_default_mac'
     The default interface's MAC address.  Read-only.  This is alias
     for the `net_${net_default_interface}_mac'.

Could you verify that it works for you? Also if you would comment on
documentation in Network section from user's perspective.



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Obtaining the MAC address of the boot NIC for a PXE boot
  2013-05-08 19:25     ` Andrey Borzenkov
@ 2013-05-10 16:12       ` Rigoberto Corujo
  2013-05-11  4:47         ` Andrey Borzenkov
  0 siblings, 1 reply; 21+ messages in thread
From: Rigoberto Corujo @ 2013-05-10 16:12 UTC (permalink / raw)
  To: Andrey Borzenkov; +Cc: help-grub, grub-devel

----- Original Message -----

> From: Andrey Borzenkov <arvidjaar@gmail.com>
> To: Rigoberto Corujo <rcorujo@yahoo.com>
> Cc: "help-grub@gnu.org" <help-grub@gnu.org>; "grub-devel@gnu.org" <grub-devel@gnu.org>
> Sent: Wednesday, May 8, 2013 3:25 PM
> Subject: Re: Obtaining the MAC address of the boot NIC for a PXE boot
> 
> В Wed, 8 May 2013 10:27:47 -0700 (PDT)
> Rigoberto Corujo <rcorujo@yahoo.com> пишет:
> 
>> 
>>  Thank you very much, Andrey.  This worked.  I did have to add the following 
> lines to "grub-core/Makefile.core.am" to get a "eval.mod" 
> generated, but I'm sure that it's probably because I missed an important 
> step that would have automatically generated it.
>> 
> 
> In the meantime Vladimir pushed different implementation that provides
> net_default_mac:
> 
> `net_default_interface'
>      Initially set to name of network interface that was used to load
>      grub.  Read-write, although setting it affects only interpretation
>      of `net_default_ip' and `net_default_mac'
> 
> `net_default_ip'
>      The IP address of default interface.  Read-only. This is alias for
>      the `net_${net_default_interface}_ip'.
> 
> `net_default_mac'
>      The default interface's MAC address.  Read-only.  This is alias
>      for the `net_${net_default_interface}_mac'.
> 
> Could you verify that it works for you? Also if you would comment on
> documentation in Network section from user's perspective.
> 
> 
> _______________________________________________
> Help-grub mailing list
> Help-grub@gnu.org
> https://lists.gnu.org/mailman/listinfo/help-grub
> 

Thank you Andrey.  I can confirm that the net_default_interface, net_default_ip, and net_default_mac variables worked as expected.  I did notice, however, then when I'm in the grub shell and I type "set", these variables show up in the list, but they have no values, which makes it appear as if something is wrong.  If I echo the variables, however, I do see their correct values.

As far as the documentation, I would suggest that for the description of net_default_mac, something similar to the following text be added:

The net_default_mac variable may be used in your GRUB configuration file as a substitute for the BOOTIF=<hardware-address-of-boot-interface> option that gets appended to the Linux kernel parameters by the pxelinux IPAPPEND option.

I think most pxelinux users that are switching to GRUB 2 will do a Google search for BOOTIF and IPAPPEND, looking to see how to obtain the boot NIC's MAC address with GRUB 2, and having those two keywords in the documentation would make it easy to find the answer.

Thank you very much, once again.

Rigoberto


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Obtaining the MAC address of the boot NIC for a PXE boot
  2013-05-10 16:12       ` Rigoberto Corujo
@ 2013-05-11  4:47         ` Andrey Borzenkov
  2013-05-15 17:09           ` Rigoberto Corujo
  0 siblings, 1 reply; 21+ messages in thread
From: Andrey Borzenkov @ 2013-05-11  4:47 UTC (permalink / raw)
  To: Rigoberto Corujo; +Cc: help-grub, grub-devel

В Fri, 10 May 2013 09:12:57 -0700 (PDT)
Rigoberto Corujo <rcorujo@yahoo.com> пишет:

> 
> Thank you Andrey.  I can confirm that the net_default_interface, net_default_ip, and net_default_mac variables worked as expected.  I did notice, however, then when I'm in the grub shell and I type "set", these variables show up in the list, but they have no values, which makes it appear as if something is wrong.  If I echo the variables, however, I do see their correct values.
> 

Does it behave better with patch below?

diff --git a/grub-core/kern/corecmd.c b/grub-core/kern/corecmd.c
index cfab676..1700eb4 100644
--- a/grub-core/kern/corecmd.c
+++ b/grub-core/kern/corecmd.c
@@ -40,7 +40,7 @@ grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)),
     {
       struct grub_env_var *env;
       FOR_SORTED_ENV (env)
-	grub_printf ("%s=%s\n", env->name, env->value);
+	grub_printf ("%s=%s\n", env->name, grub_env_get (env->name));
       return 0;
     }
 


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* New command eval.
  2013-05-04 21:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-05-04 21:19     ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-05-11 16:35     ` Andrey Borzenkov
  2013-05-11 17:02       ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-05-12  0:07       ` Seth Goldberg
  1 sibling, 2 replies; 21+ messages in thread
From: Andrey Borzenkov @ 2013-05-11 16:35 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 8406 bytes --]

В Sat, 04 May 2013 23:08:03 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> > - it adds "eval" command (same as known from UNIX shells) which
> >   executes its argument
> 
> eval is generally good
> 
> 
> > +static grub_err_t
> > +grub_cmd_eval (grub_extcmd_context_t ctxt __attribute__((__unused__)),
> > +	       int argc, char *argv[])
> > +{
> 
> You don't use any argument parsing. It's better to use command and not
> extcmd in this case. Also "eval" in bash concatenates its arguments.
> 
> > +  cmd = grub_register_extcmd ("eval", grub_cmd_eval, 0,
> > +			      N_("[STRING]"), N_("Evaluate commands"),
> 
> This description seems a bit vague for either human-reading or translation.
> 

Is patch below OK? I decided to split off pure execute_sourcecode so
that eval context would not clobber positional arguments.

diff --git a/ChangeLog b/ChangeLog
index cd8213a..8ca9874 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-05-11  Andrey Borzenkov <arvidjaar@gmail.com>
+
+	* grub-core/script/execute.c (grub_script_execute_sourcecode): Split
+	off new function grub_script_execute_new_scope. Change callers to use
+	either of them as appropriate.
+	* grub-core/commands/eval.c: New command eval.
+	* docs/grub.texi (Commands): Document it.
+
 2013-05-11  Vladimir Serbinenko  <phcoder@gmail.com>
 
 	* util/grub-install.in: Gettextize "Not found" message.
diff --git a/docs/grub.texi b/docs/grub.texi
index 75a5ea4..9dcfa2d 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -3435,6 +3435,7 @@ you forget a command, you can run the command @command{help}
 * date::                        Display or set current date and time
 * drivemap::                    Map a drive to another
 * echo::                        Display a line of text
+* eval::                        Evaluate agruments as GRUB commands
 * export::                      Export an environment variable
 * false::                       Do nothing, unsuccessfully
 * gettext::                     Translate a string
@@ -3812,6 +3813,15 @@ character will print that character.
 @end deffn
 
 
+@node eval
+@subsection eval
+
+@deffn Command eval string ...
+Concatenate arguments together using single space as separator and evaluate
+result as sequence of GRUB commands.
+@end deffn
+
+
 @node export
 @subsection export
 
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 602b497..0fcc4e7 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -699,6 +699,11 @@ module = {
 };
 
 module = {
+  name = eval;
+  common = commands/eval.c;
+};
+
+module = {
   name = extcmd;
   common = commands/extcmd.c;
   common = lib/arg.c;
diff --git a/grub-core/commands/eval.c b/grub-core/commands/eval.c
new file mode 100644
index 0000000..e514a1a
--- /dev/null
+++ b/grub-core/commands/eval.c
@@ -0,0 +1,72 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/script_sh.h>
+#include <grub/command.h>
+#include <grub/i18n.h>
+#include <grub/term.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static grub_err_t
+grub_cmd_eval (grub_command_t cmd __attribute__((__unused__)),
+	       int argc, char *argv[])
+{
+  int i;
+  grub_size_t size = argc; /* +1 for final zero */
+  char *str, *p;
+  grub_err_t ret;
+
+  if (argc == 0)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing arguments"));
+
+  for (i = 0; i < argc; i++)
+    size += grub_strlen (argv[i]);
+
+  str = p = grub_malloc (size);
+  if (!str)
+    return grub_errno;
+
+  for (i = 0; i < argc; i++)
+    {
+      grub_strcpy (p, argv[i]);
+      p += grub_strlen (argv[i]);
+      *p++ = ' ';
+    }
+  *--p = '\0';
+
+  ret = grub_script_execute_sourcecode (str);
+  grub_free (str);
+  return ret;
+}
+
+static grub_command_t cmd;
+
+GRUB_MOD_INIT(eval)
+{
+  cmd = grub_register_command ("eval", grub_cmd_eval, N_("STRING ..."),
+				N_("Evaluate arguments as GRUB commands"));
+}
+
+GRUB_MOD_FINI(eval)
+{
+  grub_unregister_command (cmd);
+}
+
diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
index fba19db..9b88290 100644
--- a/grub-core/normal/menu.c
+++ b/grub-core/normal/menu.c
@@ -245,7 +245,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot)
   else
     grub_env_unset ("default");
 
-  grub_script_execute_sourcecode (entry->sourcecode, entry->argc, entry->args);
+  grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args);
 
   if (errs_before != grub_err_printed_errors)
     grub_wait_after_message ();
diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c
index fae258a..0f15a7e 100644
--- a/grub-core/normal/menu_entry.c
+++ b/grub-core/normal/menu_entry.c
@@ -1120,7 +1120,6 @@ run (struct screen *screen)
   char *script;
   int errs_before;
   grub_menu_t menu = NULL;
-  char *dummy[1] = { NULL };
 
   grub_cls ();
   grub_printf ("  ");
@@ -1160,7 +1159,7 @@ run (struct screen *screen)
       }
     script[size] = '\0';
   }
-  grub_script_execute_sourcecode (script, 0, dummy);
+  grub_script_execute_sourcecode (script);
   grub_free (script);
 
   if (errs_before != grub_err_printed_errors)
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
index 9babbee..afd5513 100644
--- a/grub-core/script/execute.c
+++ b/grub-core/script/execute.c
@@ -856,19 +856,10 @@ grub_script_execute_sourcecode_getline (char **line,
 
 /* Execute a source script.  */
 grub_err_t
-grub_script_execute_sourcecode (const char *source, int argc, char **args)
+grub_script_execute_sourcecode (const char *source)
 {
   grub_err_t ret = 0;
   struct grub_script *parsed_script;
-  struct grub_script_scope new_scope;
-  struct grub_script_scope *old_scope;
-
-  new_scope.argv.argc = argc;
-  new_scope.argv.args = args;
-  new_scope.flags = 0;
-
-  old_scope = scope;
-  scope = &new_scope;
 
   while (source)
     {
@@ -880,13 +871,35 @@ grub_script_execute_sourcecode (const char *source, int argc, char **args)
       if (! parsed_script)
 	{
 	  ret = grub_errno;
+	  grub_free (line);
 	  break;
 	}
 
       ret = grub_script_execute (parsed_script);
+      grub_script_free (parsed_script);
       grub_free (line);
     }
 
+  return ret;
+}
+
+/* Execute a source script in new scope.  */
+grub_err_t
+grub_script_execute_new_scope (const char *source, int argc, char **args)
+{
+  grub_err_t ret = 0;
+  struct grub_script_scope new_scope;
+  struct grub_script_scope *old_scope;
+
+  new_scope.argv.argc = argc;
+  new_scope.argv.args = args;
+  new_scope.flags = 0;
+
+  old_scope = scope;
+  scope = &new_scope;
+
+  ret = grub_script_execute_sourcecode (source);
+
   scope = old_scope;
   return ret;
 }
diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h
index 78602e4..57bdd4d 100644
--- a/include/grub/script_sh.h
+++ b/include/grub/script_sh.h
@@ -329,7 +329,8 @@ grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
 
 /* Execute any GRUB pre-parsed command or script.  */
 grub_err_t grub_script_execute (struct grub_script *script);
-grub_err_t grub_script_execute_sourcecode (const char *source, int argc, char **args);
+grub_err_t grub_script_execute_sourcecode (const char *source);
+grub_err_t grub_script_execute_new_scope (const char *source, int argc, char **args);
 
 /* Break command for loops.  */
 grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: New command eval.
  2013-05-11 16:35     ` New command eval Andrey Borzenkov
@ 2013-05-11 17:02       ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-05-11 17:30         ` Andrey Borzenkov
  2013-05-12  0:07       ` Seth Goldberg
  1 sibling, 1 reply; 21+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-05-11 17:02 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

On 11.05.2013 18:35, Andrey Borzenkov wrote:

> +  grub_size_t size = argc; /* +1 for final zero */
> +  char *str, *p;
> +  grub_err_t ret;
> +
> +  if (argc == 0)
> +    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing arguments"));
> +

eval with no arguments returns success in bash, to match this behaviour,
it should be GRUB_ERR_NONE and no use of grub_error

> +  for (i = 0; i < argc; i++)
> +    size += grub_strlen (argv[i]);
> +
> +  str = p = grub_malloc (size);
> +  if (!str)
> +    return grub_errno;
> +
> +  for (i = 0; i < argc; i++)
> +    {
> +      grub_strcpy (p, argv[i]);
> +      p += grub_strlen (argv[i]);

These 2 operations should be condensed by using grub_stpcpy

> +      *p++ = ' ';


>-  grub_script_execute_sourcecode (script, 0, dummy);
>+  grub_script_execute_sourcecode (script);
(in menu_entry.c) here you need a new scope for consistency.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: New command eval.
  2013-05-11 17:02       ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-05-11 17:30         ` Andrey Borzenkov
  2013-05-14  6:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 21+ messages in thread
From: Andrey Borzenkov @ 2013-05-11 17:30 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 8357 bytes --]

В Sat, 11 May 2013 19:02:58 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> On 11.05.2013 18:35, Andrey Borzenkov wrote:
> 
> > +  grub_size_t size = argc; /* +1 for final zero */
> > +  char *str, *p;
> > +  grub_err_t ret;
> > +
> > +  if (argc == 0)
> > +    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing arguments"));
> > +
> 
> eval with no arguments returns success in bash, to match this behaviour,
> it should be GRUB_ERR_NONE and no use of grub_error
> 
> > +  for (i = 0; i < argc; i++)
> > +    size += grub_strlen (argv[i]);
> > +
> > +  str = p = grub_malloc (size);
> > +  if (!str)
> > +    return grub_errno;
> > +
> > +  for (i = 0; i < argc; i++)
> > +    {
> > +      grub_strcpy (p, argv[i]);
> > +      p += grub_strlen (argv[i]);
> 
> These 2 operations should be condensed by using grub_stpcpy
> 
> > +      *p++ = ' ';
> 
> 
> >-  grub_script_execute_sourcecode (script, 0, dummy);
> >+  grub_script_execute_sourcecode (script);
> (in menu_entry.c) here you need a new scope for consistency.
> 

diff --git a/ChangeLog b/ChangeLog
index cd8213a..60c64ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-05-11  Andrey Borzenkov <arvidjaar@gmail.com>
+
+	* grub-core/script/execute.c (grub_script_execute_sourcecode): Split
+	off new function grub_script_execute_new_scope. Change callers to use
+	either of them as appropriate.
+	* grub-core/commands/eval.c: New command eval.
+	* docs/grub.texi (Commands): Document it.
+
 2013-05-11  Vladimir Serbinenko  <phcoder@gmail.com>
 
 	* util/grub-install.in: Gettextize "Not found" message.
diff --git a/docs/grub.texi b/docs/grub.texi
index 75a5ea4..9dcfa2d 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -3435,6 +3435,7 @@ you forget a command, you can run the command @command{help}
 * date::                        Display or set current date and time
 * drivemap::                    Map a drive to another
 * echo::                        Display a line of text
+* eval::                        Evaluate agruments as GRUB commands
 * export::                      Export an environment variable
 * false::                       Do nothing, unsuccessfully
 * gettext::                     Translate a string
@@ -3812,6 +3813,15 @@ character will print that character.
 @end deffn
 
 
+@node eval
+@subsection eval
+
+@deffn Command eval string ...
+Concatenate arguments together using single space as separator and evaluate
+result as sequence of GRUB commands.
+@end deffn
+
+
 @node export
 @subsection export
 
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 602b497..0fcc4e7 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -699,6 +699,11 @@ module = {
 };
 
 module = {
+  name = eval;
+  common = commands/eval.c;
+};
+
+module = {
   name = extcmd;
   common = commands/extcmd.c;
   common = lib/arg.c;
diff --git a/grub-core/commands/eval.c b/grub-core/commands/eval.c
new file mode 100644
index 0000000..f826a4f
--- /dev/null
+++ b/grub-core/commands/eval.c
@@ -0,0 +1,71 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/script_sh.h>
+#include <grub/command.h>
+#include <grub/i18n.h>
+#include <grub/term.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static grub_err_t
+grub_cmd_eval (grub_command_t cmd __attribute__((__unused__)),
+	       int argc, char *argv[])
+{
+  int i;
+  grub_size_t size = argc; /* +1 for final zero */
+  char *str, *p;
+  grub_err_t ret;
+
+  if (argc == 0)
+    return GRUB_ERR_NONE;
+
+  for (i = 0; i < argc; i++)
+    size += grub_strlen (argv[i]);
+
+  str = p = grub_malloc (size);
+  if (!str)
+    return grub_errno;
+
+  for (i = 0; i < argc; i++)
+    {
+      p = grub_stpcpy (p, argv[i]);
+      *p++ = ' ';
+    }
+  *--p = '\0';
+
+  ret = grub_script_execute_sourcecode (str);
+  grub_free (str);
+  return ret;
+}
+
+static grub_command_t cmd;
+
+GRUB_MOD_INIT(eval)
+{
+  cmd = grub_register_command ("eval", grub_cmd_eval, N_("STRING ..."),
+				N_("Evaluate arguments as GRUB commands"));
+}
+
+GRUB_MOD_FINI(eval)
+{
+  grub_unregister_command (cmd);
+}
+
diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
index fba19db..9b88290 100644
--- a/grub-core/normal/menu.c
+++ b/grub-core/normal/menu.c
@@ -245,7 +245,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot)
   else
     grub_env_unset ("default");
 
-  grub_script_execute_sourcecode (entry->sourcecode, entry->argc, entry->args);
+  grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args);
 
   if (errs_before != grub_err_printed_errors)
     grub_wait_after_message ();
diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c
index fae258a..506715c 100644
--- a/grub-core/normal/menu_entry.c
+++ b/grub-core/normal/menu_entry.c
@@ -1160,7 +1160,7 @@ run (struct screen *screen)
       }
     script[size] = '\0';
   }
-  grub_script_execute_sourcecode (script, 0, dummy);
+  grub_script_execute_new_scope (script, 0, dummy);
   grub_free (script);
 
   if (errs_before != grub_err_printed_errors)
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
index 9babbee..afd5513 100644
--- a/grub-core/script/execute.c
+++ b/grub-core/script/execute.c
@@ -856,19 +856,10 @@ grub_script_execute_sourcecode_getline (char **line,
 
 /* Execute a source script.  */
 grub_err_t
-grub_script_execute_sourcecode (const char *source, int argc, char **args)
+grub_script_execute_sourcecode (const char *source)
 {
   grub_err_t ret = 0;
   struct grub_script *parsed_script;
-  struct grub_script_scope new_scope;
-  struct grub_script_scope *old_scope;
-
-  new_scope.argv.argc = argc;
-  new_scope.argv.args = args;
-  new_scope.flags = 0;
-
-  old_scope = scope;
-  scope = &new_scope;
 
   while (source)
     {
@@ -880,13 +871,35 @@ grub_script_execute_sourcecode (const char *source, int argc, char **args)
       if (! parsed_script)
 	{
 	  ret = grub_errno;
+	  grub_free (line);
 	  break;
 	}
 
       ret = grub_script_execute (parsed_script);
+      grub_script_free (parsed_script);
       grub_free (line);
     }
 
+  return ret;
+}
+
+/* Execute a source script in new scope.  */
+grub_err_t
+grub_script_execute_new_scope (const char *source, int argc, char **args)
+{
+  grub_err_t ret = 0;
+  struct grub_script_scope new_scope;
+  struct grub_script_scope *old_scope;
+
+  new_scope.argv.argc = argc;
+  new_scope.argv.args = args;
+  new_scope.flags = 0;
+
+  old_scope = scope;
+  scope = &new_scope;
+
+  ret = grub_script_execute_sourcecode (source);
+
   scope = old_scope;
   return ret;
 }
diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h
index 78602e4..57bdd4d 100644
--- a/include/grub/script_sh.h
+++ b/include/grub/script_sh.h
@@ -329,7 +329,8 @@ grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
 
 /* Execute any GRUB pre-parsed command or script.  */
 grub_err_t grub_script_execute (struct grub_script *script);
-grub_err_t grub_script_execute_sourcecode (const char *source, int argc, char **args);
+grub_err_t grub_script_execute_sourcecode (const char *source);
+grub_err_t grub_script_execute_new_scope (const char *source, int argc, char **args);
 
 /* Break command for loops.  */
 grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: New command eval.
  2013-05-11 16:35     ` New command eval Andrey Borzenkov
  2013-05-11 17:02       ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-05-12  0:07       ` Seth Goldberg
  2013-05-12  5:39         ` Andrey Borzenkov
  2013-05-14  7:21         ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 2 replies; 21+ messages in thread
From: Seth Goldberg @ 2013-05-12  0:07 UTC (permalink / raw)
  To: The development of GNU GRUB

Hi,

  What about the feature environment variable to allow dynamic detection of this enhancement?

  --S

On May 11, 2013, at 9:35 AM, Andrey Borzenkov <arvidjaar@gmail.com> wrote:

> В Sat, 04 May 2013 23:08:03 +0200
> Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
> 
>>> - it adds "eval" command (same as known from UNIX shells) which
>>>  executes its argument
>> 
>> eval is generally good
>> 
>> 
>>> +static grub_err_t
>>> +grub_cmd_eval (grub_extcmd_context_t ctxt __attribute__((__unused__)),
>>> +           int argc, char *argv[])
>>> +{
>> 
>> You don't use any argument parsing. It's better to use command and not
>> extcmd in this case. Also "eval" in bash concatenates its arguments.
>> 
>>> +  cmd = grub_register_extcmd ("eval", grub_cmd_eval, 0,
>>> +                  N_("[STRING]"), N_("Evaluate commands"),
>> 
>> This description seems a bit vague for either human-reading or translation.
> 
> Is patch below OK? I decided to split off pure execute_sourcecode so
> that eval context would not clobber positional arguments.
> 
> diff --git a/ChangeLog b/ChangeLog
> index cd8213a..8ca9874 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,11 @@
> +2013-05-11  Andrey Borzenkov <arvidjaar@gmail.com>
> +
> +    * grub-core/script/execute.c (grub_script_execute_sourcecode): Split
> +    off new function grub_script_execute_new_scope. Change callers to use
> +    either of them as appropriate.
> +    * grub-core/commands/eval.c: New command eval.
> +    * docs/grub.texi (Commands): Document it.
> +
> 2013-05-11  Vladimir Serbinenko  <phcoder@gmail.com>
> 
>    * util/grub-install.in: Gettextize "Not found" message.
> diff --git a/docs/grub.texi b/docs/grub.texi
> index 75a5ea4..9dcfa2d 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -3435,6 +3435,7 @@ you forget a command, you can run the command @command{help}
> * date::                        Display or set current date and time
> * drivemap::                    Map a drive to another
> * echo::                        Display a line of text
> +* eval::                        Evaluate agruments as GRUB commands
> * export::                      Export an environment variable
> * false::                       Do nothing, unsuccessfully
> * gettext::                     Translate a string
> @@ -3812,6 +3813,15 @@ character will print that character.
> @end deffn
> 
> 
> +@node eval
> +@subsection eval
> +
> +@deffn Command eval string ...
> +Concatenate arguments together using single space as separator and evaluate
> +result as sequence of GRUB commands.
> +@end deffn
> +
> +
> @node export
> @subsection export
> 
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index 602b497..0fcc4e7 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -699,6 +699,11 @@ module = {
> };
> 
> module = {
> +  name = eval;
> +  common = commands/eval.c;
> +};
> +
> +module = {
>   name = extcmd;
>   common = commands/extcmd.c;
>   common = lib/arg.c;
> diff --git a/grub-core/commands/eval.c b/grub-core/commands/eval.c
> new file mode 100644
> index 0000000..e514a1a
> --- /dev/null
> +++ b/grub-core/commands/eval.c
> @@ -0,0 +1,72 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2009  Free Software Foundation, Inc.
> + *
> + *  GRUB is free software: you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation, either version 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <grub/dl.h>
> +#include <grub/misc.h>
> +#include <grub/script_sh.h>
> +#include <grub/command.h>
> +#include <grub/i18n.h>
> +#include <grub/term.h>
> +
> +GRUB_MOD_LICENSE ("GPLv3+");
> +
> +static grub_err_t
> +grub_cmd_eval (grub_command_t cmd __attribute__((__unused__)),
> +           int argc, char *argv[])
> +{
> +  int i;
> +  grub_size_t size = argc; /* +1 for final zero */
> +  char *str, *p;
> +  grub_err_t ret;
> +
> +  if (argc == 0)
> +    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing arguments"));
> +
> +  for (i = 0; i < argc; i++)
> +    size += grub_strlen (argv[i]);
> +
> +  str = p = grub_malloc (size);
> +  if (!str)
> +    return grub_errno;
> +
> +  for (i = 0; i < argc; i++)
> +    {
> +      grub_strcpy (p, argv[i]);
> +      p += grub_strlen (argv[i]);
> +      *p++ = ' ';
> +    }
> +  *--p = '\0';
> +
> +  ret = grub_script_execute_sourcecode (str);
> +  grub_free (str);
> +  return ret;
> +}
> +
> +static grub_command_t cmd;
> +
> +GRUB_MOD_INIT(eval)
> +{
> +  cmd = grub_register_command ("eval", grub_cmd_eval, N_("STRING ..."),
> +                N_("Evaluate arguments as GRUB commands"));
> +}
> +
> +GRUB_MOD_FINI(eval)
> +{
> +  grub_unregister_command (cmd);
> +}
> +
> diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
> index fba19db..9b88290 100644
> --- a/grub-core/normal/menu.c
> +++ b/grub-core/normal/menu.c
> @@ -245,7 +245,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot)
>   else
>     grub_env_unset ("default");
> 
> -  grub_script_execute_sourcecode (entry->sourcecode, entry->argc, entry->args);
> +  grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args);
> 
>   if (errs_before != grub_err_printed_errors)
>     grub_wait_after_message ();
> diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c
> index fae258a..0f15a7e 100644
> --- a/grub-core/normal/menu_entry.c
> +++ b/grub-core/normal/menu_entry.c
> @@ -1120,7 +1120,6 @@ run (struct screen *screen)
>   char *script;
>   int errs_before;
>   grub_menu_t menu = NULL;
> -  char *dummy[1] = { NULL };
> 
>   grub_cls ();
>   grub_printf ("  ");
> @@ -1160,7 +1159,7 @@ run (struct screen *screen)
>       }
>     script[size] = '\0';
>   }
> -  grub_script_execute_sourcecode (script, 0, dummy);
> +  grub_script_execute_sourcecode (script);
>   grub_free (script);
> 
>   if (errs_before != grub_err_printed_errors)
> diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
> index 9babbee..afd5513 100644
> --- a/grub-core/script/execute.c
> +++ b/grub-core/script/execute.c
> @@ -856,19 +856,10 @@ grub_script_execute_sourcecode_getline (char **line,
> 
> /* Execute a source script.  */
> grub_err_t
> -grub_script_execute_sourcecode (const char *source, int argc, char **args)
> +grub_script_execute_sourcecode (const char *source)
> {
>   grub_err_t ret = 0;
>   struct grub_script *parsed_script;
> -  struct grub_script_scope new_scope;
> -  struct grub_script_scope *old_scope;
> -
> -  new_scope.argv.argc = argc;
> -  new_scope.argv.args = args;
> -  new_scope.flags = 0;
> -
> -  old_scope = scope;
> -  scope = &new_scope;
> 
>   while (source)
>     {
> @@ -880,13 +871,35 @@ grub_script_execute_sourcecode (const char *source, int argc, char **args)
>       if (! parsed_script)
>    {
>      ret = grub_errno;
> +      grub_free (line);
>      break;
>    }
> 
>       ret = grub_script_execute (parsed_script);
> +      grub_script_free (parsed_script);
>       grub_free (line);
>     }
> 
> +  return ret;
> +}
> +
> +/* Execute a source script in new scope.  */
> +grub_err_t
> +grub_script_execute_new_scope (const char *source, int argc, char **args)
> +{
> +  grub_err_t ret = 0;
> +  struct grub_script_scope new_scope;
> +  struct grub_script_scope *old_scope;
> +
> +  new_scope.argv.argc = argc;
> +  new_scope.argv.args = args;
> +  new_scope.flags = 0;
> +
> +  old_scope = scope;
> +  scope = &new_scope;
> +
> +  ret = grub_script_execute_sourcecode (source);
> +
>   scope = old_scope;
>   return ret;
> }
> diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h
> index 78602e4..57bdd4d 100644
> --- a/include/grub/script_sh.h
> +++ b/include/grub/script_sh.h
> @@ -329,7 +329,8 @@ grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
> 
> /* Execute any GRUB pre-parsed command or script.  */
> grub_err_t grub_script_execute (struct grub_script *script);
> -grub_err_t grub_script_execute_sourcecode (const char *source, int argc, char **args);
> +grub_err_t grub_script_execute_sourcecode (const char *source);
> +grub_err_t grub_script_execute_new_scope (const char *source, int argc, char **args);
> 
> /* Break command for loops.  */
> grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: New command eval.
  2013-05-12  0:07       ` Seth Goldberg
@ 2013-05-12  5:39         ` Andrey Borzenkov
  2013-05-13  5:13           ` Seth Goldberg
  2013-05-14  7:21         ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 1 reply; 21+ messages in thread
From: Andrey Borzenkov @ 2013-05-12  5:39 UTC (permalink / raw)
  To: grub-devel

В Sat, 11 May 2013 17:07:19 -0700
Seth Goldberg <seth.goldberg@oracle.com> пишет:

> Hi,
> 
>   What about the feature environment variable to allow dynamic detection of this enhancement?
> 

That really does not scale. Commands come and go. What about single
command "has" (or probably better "implements") as in

implements --command eval|testspeed|...
implements --crypto_algorithm sha256|...
implements --network_protocol http|tftp|ipv6|...

Command "implements" itself may be instantiated under
fetature_201_final (or whatever next version is).

It probably could even be extended to feature test of single commands,
like

implements --command menuentry --feature id


Note that in this specific case (eval) this probably is not useful at
all. If you want to test whether this command is present, you
presumably are going to write alternative implementation without eval.
In this case why bother to test in the first place?


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: New command eval.
  2013-05-12  5:39         ` Andrey Borzenkov
@ 2013-05-13  5:13           ` Seth Goldberg
  0 siblings, 0 replies; 21+ messages in thread
From: Seth Goldberg @ 2013-05-13  5:13 UTC (permalink / raw)
  To: The development of GNU GRUB


On May 11, 2013, at 10:39 PM, Andrey Borzenkov wrote:

> В Sat, 11 May 2013 17:07:19 -0700
> Seth Goldberg <seth.goldberg@oracle.com> пишет:
> 
>> Hi,
>> 
>>  What about the feature environment variable to allow dynamic detection of this enhancement?
>> 
> 
> That really does not scale. Commands come and go. What about single
> command "has" (or probably better "implements") as in

  That's what we've had thus far, which is why I'm referring to it.  Existing script that has to run regardless of the version of GRUB will continue to need to refer to the existing feature vars.  Going forward, I'm OK with your scheme.

 --S

> 
> implements --command eval|testspeed|...
> implements --crypto_algorithm sha256|...
> implements --network_protocol http|tftp|ipv6|...
> 
> Command "implements" itself may be instantiated under
> fetature_201_final (or whatever next version is).
> 
> It probably could even be extended to feature test of single commands,
> like
> 
> implements --command menuentry --feature id
> 
> 
> Note that in this specific case (eval) this probably is not useful at
> all. If you want to test whether this command is present, you
> presumably are going to write alternative implementation without eval.
> In this case why bother to test in the first place?
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: New command eval.
  2013-05-11 17:30         ` Andrey Borzenkov
@ 2013-05-14  6:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 21+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-05-14  6:26 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 9145 bytes --]

Patch is good. Could you add corresponding testcase to testsuite and commit?
On 11.05.2013 19:30, Andrey Borzenkov wrote:

> В Sat, 11 May 2013 19:02:58 +0200
> Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
> 
>> On 11.05.2013 18:35, Andrey Borzenkov wrote:
>>
>>> +  grub_size_t size = argc; /* +1 for final zero */
>>> +  char *str, *p;
>>> +  grub_err_t ret;
>>> +
>>> +  if (argc == 0)
>>> +    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing arguments"));
>>> +
>>
>> eval with no arguments returns success in bash, to match this behaviour,
>> it should be GRUB_ERR_NONE and no use of grub_error
>>
>>> +  for (i = 0; i < argc; i++)
>>> +    size += grub_strlen (argv[i]);
>>> +
>>> +  str = p = grub_malloc (size);
>>> +  if (!str)
>>> +    return grub_errno;
>>> +
>>> +  for (i = 0; i < argc; i++)
>>> +    {
>>> +      grub_strcpy (p, argv[i]);
>>> +      p += grub_strlen (argv[i]);
>>
>> These 2 operations should be condensed by using grub_stpcpy
>>
>>> +      *p++ = ' ';
>>
>>
>>> -  grub_script_execute_sourcecode (script, 0, dummy);
>>> +  grub_script_execute_sourcecode (script);
>> (in menu_entry.c) here you need a new scope for consistency.
>>
> 
> diff --git a/ChangeLog b/ChangeLog
> index cd8213a..60c64ee 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,11 @@
> +2013-05-11  Andrey Borzenkov <arvidjaar@gmail.com>
> +
> +	* grub-core/script/execute.c (grub_script_execute_sourcecode): Split
> +	off new function grub_script_execute_new_scope. Change callers to use
> +	either of them as appropriate.
> +	* grub-core/commands/eval.c: New command eval.
> +	* docs/grub.texi (Commands): Document it.
> +
>  2013-05-11  Vladimir Serbinenko  <phcoder@gmail.com>
>  
>  	* util/grub-install.in: Gettextize "Not found" message.
> diff --git a/docs/grub.texi b/docs/grub.texi
> index 75a5ea4..9dcfa2d 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -3435,6 +3435,7 @@ you forget a command, you can run the command @command{help}
>  * date::                        Display or set current date and time
>  * drivemap::                    Map a drive to another
>  * echo::                        Display a line of text
> +* eval::                        Evaluate agruments as GRUB commands
>  * export::                      Export an environment variable
>  * false::                       Do nothing, unsuccessfully
>  * gettext::                     Translate a string
> @@ -3812,6 +3813,15 @@ character will print that character.
>  @end deffn
>  
>  
> +@node eval
> +@subsection eval
> +
> +@deffn Command eval string ...
> +Concatenate arguments together using single space as separator and evaluate
> +result as sequence of GRUB commands.
> +@end deffn
> +
> +
>  @node export
>  @subsection export
>  
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index 602b497..0fcc4e7 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -699,6 +699,11 @@ module = {
>  };
>  
>  module = {
> +  name = eval;
> +  common = commands/eval.c;
> +};
> +
> +module = {
>    name = extcmd;
>    common = commands/extcmd.c;
>    common = lib/arg.c;
> diff --git a/grub-core/commands/eval.c b/grub-core/commands/eval.c
> new file mode 100644
> index 0000000..f826a4f
> --- /dev/null
> +++ b/grub-core/commands/eval.c
> @@ -0,0 +1,71 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2009  Free Software Foundation, Inc.
> + *
> + *  GRUB is free software: you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation, either version 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <grub/dl.h>
> +#include <grub/misc.h>
> +#include <grub/script_sh.h>
> +#include <grub/command.h>
> +#include <grub/i18n.h>
> +#include <grub/term.h>
> +
> +GRUB_MOD_LICENSE ("GPLv3+");
> +
> +static grub_err_t
> +grub_cmd_eval (grub_command_t cmd __attribute__((__unused__)),
> +	       int argc, char *argv[])
> +{
> +  int i;
> +  grub_size_t size = argc; /* +1 for final zero */
> +  char *str, *p;
> +  grub_err_t ret;
> +
> +  if (argc == 0)
> +    return GRUB_ERR_NONE;
> +
> +  for (i = 0; i < argc; i++)
> +    size += grub_strlen (argv[i]);
> +
> +  str = p = grub_malloc (size);
> +  if (!str)
> +    return grub_errno;
> +
> +  for (i = 0; i < argc; i++)
> +    {
> +      p = grub_stpcpy (p, argv[i]);
> +      *p++ = ' ';
> +    }
> +  *--p = '\0';
> +
> +  ret = grub_script_execute_sourcecode (str);
> +  grub_free (str);
> +  return ret;
> +}
> +
> +static grub_command_t cmd;
> +
> +GRUB_MOD_INIT(eval)
> +{
> +  cmd = grub_register_command ("eval", grub_cmd_eval, N_("STRING ..."),
> +				N_("Evaluate arguments as GRUB commands"));
> +}
> +
> +GRUB_MOD_FINI(eval)
> +{
> +  grub_unregister_command (cmd);
> +}
> +
> diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
> index fba19db..9b88290 100644
> --- a/grub-core/normal/menu.c
> +++ b/grub-core/normal/menu.c
> @@ -245,7 +245,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot)
>    else
>      grub_env_unset ("default");
>  
> -  grub_script_execute_sourcecode (entry->sourcecode, entry->argc, entry->args);
> +  grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args);
>  
>    if (errs_before != grub_err_printed_errors)
>      grub_wait_after_message ();
> diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c
> index fae258a..506715c 100644
> --- a/grub-core/normal/menu_entry.c
> +++ b/grub-core/normal/menu_entry.c
> @@ -1160,7 +1160,7 @@ run (struct screen *screen)
>        }
>      script[size] = '\0';
>    }
> -  grub_script_execute_sourcecode (script, 0, dummy);
> +  grub_script_execute_new_scope (script, 0, dummy);
>    grub_free (script);
>  
>    if (errs_before != grub_err_printed_errors)
> diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
> index 9babbee..afd5513 100644
> --- a/grub-core/script/execute.c
> +++ b/grub-core/script/execute.c
> @@ -856,19 +856,10 @@ grub_script_execute_sourcecode_getline (char **line,
>  
>  /* Execute a source script.  */
>  grub_err_t
> -grub_script_execute_sourcecode (const char *source, int argc, char **args)
> +grub_script_execute_sourcecode (const char *source)
>  {
>    grub_err_t ret = 0;
>    struct grub_script *parsed_script;
> -  struct grub_script_scope new_scope;
> -  struct grub_script_scope *old_scope;
> -
> -  new_scope.argv.argc = argc;
> -  new_scope.argv.args = args;
> -  new_scope.flags = 0;
> -
> -  old_scope = scope;
> -  scope = &new_scope;
>  
>    while (source)
>      {
> @@ -880,13 +871,35 @@ grub_script_execute_sourcecode (const char *source, int argc, char **args)
>        if (! parsed_script)
>  	{
>  	  ret = grub_errno;
> +	  grub_free (line);
>  	  break;
>  	}
>  
>        ret = grub_script_execute (parsed_script);
> +      grub_script_free (parsed_script);
>        grub_free (line);
>      }
>  
> +  return ret;
> +}
> +
> +/* Execute a source script in new scope.  */
> +grub_err_t
> +grub_script_execute_new_scope (const char *source, int argc, char **args)
> +{
> +  grub_err_t ret = 0;
> +  struct grub_script_scope new_scope;
> +  struct grub_script_scope *old_scope;
> +
> +  new_scope.argv.argc = argc;
> +  new_scope.argv.args = args;
> +  new_scope.flags = 0;
> +
> +  old_scope = scope;
> +  scope = &new_scope;
> +
> +  ret = grub_script_execute_sourcecode (source);
> +
>    scope = old_scope;
>    return ret;
>  }
> diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h
> index 78602e4..57bdd4d 100644
> --- a/include/grub/script_sh.h
> +++ b/include/grub/script_sh.h
> @@ -329,7 +329,8 @@ grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
>  
>  /* Execute any GRUB pre-parsed command or script.  */
>  grub_err_t grub_script_execute (struct grub_script *script);
> -grub_err_t grub_script_execute_sourcecode (const char *source, int argc, char **args);
> +grub_err_t grub_script_execute_sourcecode (const char *source);
> +grub_err_t grub_script_execute_new_scope (const char *source, int argc, char **args);
>  
>  /* Break command for loops.  */
>  grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);
> 
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: New command eval.
  2013-05-12  0:07       ` Seth Goldberg
  2013-05-12  5:39         ` Andrey Borzenkov
@ 2013-05-14  7:21         ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 21+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-05-14  7:21 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 294 bytes --]

On 12.05.2013 02:07, Seth Goldberg wrote:

> Hi,
> 
>   What about the feature environment variable to allow dynamic detection of this enhancement?


if eval; then
   # Use eval
else
   # Don't use eval
fi

Or

if eval true; then
   # Use eval
else
   # Don't use eval
fi


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Obtaining the MAC address of the boot NIC for a PXE boot
  2013-05-11  4:47         ` Andrey Borzenkov
@ 2013-05-15 17:09           ` Rigoberto Corujo
  0 siblings, 0 replies; 21+ messages in thread
From: Rigoberto Corujo @ 2013-05-15 17:09 UTC (permalink / raw)
  To: Andrey Borzenkov; +Cc: help-grub, grub-devel

>________________________________
> From: Andrey Borzenkov <arvidjaar@gmail.com>
>To: Rigoberto Corujo <rcorujo@yahoo.com> 
>Cc: "help-grub@gnu.org" <help-grub@gnu.org>; "grub-devel@gnu.org" <grub-devel@gnu.org> 
>Sent: Saturday, May 11, 2013 12:47 AM
>Subject: Re: Obtaining the MAC address of the boot NIC for a PXE boot
> 
>
>В Fri, 10 May 2013 09:12:57 -0700 (PDT)
>Rigoberto Corujo <rcorujo@yahoo.com> пишет:
>
>> 
>> Thank you Andrey.  I can confirm that the net_default_interface, net_default_ip, and net_default_mac variables worked as expected.  I did notice, however, then when I'm in the grub shell and I type "set", these variables show up in the list, but they have no values, which makes it appear as if something is wrong.  If I echo the variables, however, I do see their correct values.
>> 
>
>Does it behave better with patch below?
>
>diff --git a/grub-core/kern/corecmd.c b/grub-core/kern/corecmd.c
>index cfab676..1700eb4 100644
>--- a/grub-core/kern/corecmd.c
>+++ b/grub-core/kern/corecmd.c
>@@ -40,7 +40,7 @@ grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)),
>     {
>       struct grub_env_var *env;
>       FOR_SORTED_ENV (env)
>-    grub_printf ("%s=%s\n", env->name, env->value);
>+    grub_printf ("%s=%s\n", env->name, grub_env_get (env->name));
>       return 0;
>     }
>


Yes, Andrey.  With the patch, I can now see the values of the net_default_interface, net_default_ip, and net_default_mac variables when I type "set" at the grub shell.

Thank you.

Rigoberto


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2013-05-15 17:09 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1367240132.58582.YahooMailNeo@web120204.mail.ne1.yahoo.com>
2013-05-01 14:59 ` Obtaining the MAC address of the boot NIC for a PXE boot Andrey Borzenkov
2013-05-04 21:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-04 21:19     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-05  5:17       ` Andrey Borzenkov
2013-05-07 10:03         ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-07 17:50           ` Documentation for (Re: Obtaining the MAC address of the boot NIC for a PXE boot) Andrey Borzenkov
2013-05-07 19:45             ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-08 14:52               ` Andrey Borzenkov
2013-05-11 16:35     ` New command eval Andrey Borzenkov
2013-05-11 17:02       ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-11 17:30         ` Andrey Borzenkov
2013-05-14  6:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-12  0:07       ` Seth Goldberg
2013-05-12  5:39         ` Andrey Borzenkov
2013-05-13  5:13           ` Seth Goldberg
2013-05-14  7:21         ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-08 17:27   ` Obtaining the MAC address of the boot NIC for a PXE boot Rigoberto Corujo
2013-05-08 19:25     ` Andrey Borzenkov
2013-05-10 16:12       ` Rigoberto Corujo
2013-05-11  4:47         ` Andrey Borzenkov
2013-05-15 17:09           ` Rigoberto Corujo

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.