* grub-core/fs/i386/pc/pxe.c (set_mac_env): Export variable.

(set_env_limn_ro): Likewise.
	(GRUB_MOD_INIT): Likewise.
	* grub-core/hook/datehook.c (GRUB_MOD_INIT): Likewise. Change to
	ARRAY_SIZE while on it.
	(GRUB_MOD_FINI): Change to ARRAY_SIZE.
	* grub-core/normal/context.c (grub_env_export): Move from here ...
	* grub-core/kern/env.c (grub_env_export): ... here.
	* grub-core/normal/context.c (grub_cmd_export): Skip exporting root and
	prefix.
	* grub-core/kern/main.c (grub_main): Export root and prefix.
	* include/grub/env.h (grub_env_export): Export.
	Reported by: Seth Goldberg.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-01-11 11:51:05 +01:00
parent 4514605726
commit 4531a206a1
7 changed files with 57 additions and 30 deletions

View file

@ -1,3 +1,19 @@
2011-01-11 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/i386/pc/pxe.c (set_mac_env): Export variable.
(set_env_limn_ro): Likewise.
(GRUB_MOD_INIT): Likewise.
* grub-core/hook/datehook.c (GRUB_MOD_INIT): Likewise. Change to
ARRAY_SIZE while on it.
(GRUB_MOD_FINI): Change to ARRAY_SIZE.
* grub-core/normal/context.c (grub_env_export): Move from here ...
* grub-core/kern/env.c (grub_env_export): ... here.
* grub-core/normal/context.c (grub_cmd_export): Skip exporting root and
prefix.
* grub-core/kern/main.c (grub_main): Export root and prefix.
* include/grub/env.h (grub_env_export): Export.
Reported by: Seth Goldberg.
2011-01-11 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi):

View file

@ -420,6 +420,7 @@ set_mac_env (grub_uint8_t *mac_addr, grub_size_t mac_len)
grub_env_set ("net_pxe_mac", buf);
/* XXX: Is it possible to change MAC in PXE? */
grub_register_variable_hook ("net_pxe_mac", 0, grub_env_write_readonly);
grub_env_export ("net_pxe_mac");
}
static void
@ -431,6 +432,7 @@ set_env_limn_ro (const char *varname, char *value, grub_size_t len)
grub_env_set (varname, value);
value[len] = c;
grub_register_variable_hook (varname, 0, grub_env_write_readonly);
grub_env_export (varname);
}
static void
@ -624,12 +626,19 @@ GRUB_MOD_INIT(pxe)
grub_env_write_pxe_default_server);
grub_register_variable_hook ("pxe_default_gateway", 0,
grub_env_write_pxe_default_gateway);
/* XXX: Is it possible to change IP in PXE? */
grub_register_variable_hook ("net_pxe_ip", 0,
grub_env_write_readonly);
grub_register_variable_hook ("pxe_blksize", 0,
grub_env_write_pxe_blocksize);
grub_env_export ("pxe_default_server");
grub_env_export ("pxe_default_gateway");
grub_env_export ("net_pxe_ip");
grub_env_export ("pxe_blksize");
grub_disk_dev_register (&grub_pxe_dev);
grub_fs_register (&grub_pxefs_fs);
}

View file

@ -86,18 +86,21 @@ grub_read_hook_datetime (struct grub_env_var *var,
GRUB_MOD_INIT(datehook)
{
int i;
unsigned i;
for (i = 0; i < 7; i++)
grub_register_variable_hook (grub_datetime_names[i],
grub_read_hook_datetime, 0);
for (i = 0; i < ARRAY_SIZE (grub_datetime_names); i++)
{
grub_register_variable_hook (grub_datetime_names[i],
grub_read_hook_datetime, 0);
grub_env_export (grub_datetime_names[i]);
}
}
GRUB_MOD_FINI(datehook)
{
int i;
unsigned i;
for (i = 0; i < 7; i++)
for (i = 0; i < ARRAY_SIZE (grub_datetime_names); i++)
{
grub_register_variable_hook (grub_datetime_names[i], 0, 0);
grub_env_unset (grub_datetime_names[i]);

View file

@ -240,3 +240,23 @@ grub_register_variable_hook (const char *name,
return GRUB_ERR_NONE;
}
grub_err_t
grub_env_export (const char *name)
{
struct grub_env_var *var;
var = grub_env_find (name);
if (! var)
{
grub_err_t err;
err = grub_env_set (name, "");
if (err)
return err;
var = grub_env_find (name);
}
var->global = 1;
return GRUB_ERR_NONE;
}

View file

@ -189,6 +189,8 @@ grub_main (void)
for convenience. */
grub_machine_set_prefix ();
grub_set_root_dev ();
grub_env_export ("root");
grub_env_export ("prefix");
grub_register_core_commands ();

View file

@ -175,26 +175,6 @@ grub_env_extractor_close (int source)
return err;
}
grub_err_t
grub_env_export (const char *name)
{
struct grub_env_var *var;
var = grub_env_find (name);
if (! var)
{
grub_err_t err;
err = grub_env_set (name, "");
if (err)
return err;
var = grub_env_find (name);
}
var->global = 1;
return GRUB_ERR_NONE;
}
static grub_command_t export_cmd;
static grub_err_t
@ -216,9 +196,6 @@ grub_cmd_export (struct grub_command *cmd __attribute__ ((unused)),
void
grub_context_init (void)
{
grub_env_export ("root");
grub_env_export ("prefix");
export_cmd = grub_register_command ("export", grub_cmd_export,
N_("ENVVAR [ENVVAR] ..."),
N_("Export variables."));

View file

@ -53,7 +53,7 @@ grub_err_t EXPORT_FUNC(grub_register_variable_hook) (const char *name,
grub_err_t grub_env_context_open (void);
grub_err_t grub_env_context_close (void);
grub_err_t grub_env_export (const char *name);
grub_err_t EXPORT_FUNC(grub_env_export) (const char *name);
void grub_env_unset_menu (void);
grub_menu_t grub_env_get_menu (void);