2009-02-13 20:06:27 +00:00
|
|
|
/* menu.c - General supporting functionality for menus. */
|
2003-01-20 04:13:46 +00:00
|
|
|
/*
|
2004-04-04 13:46:03 +00:00
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-20 02:50:36 +00:00
|
|
|
* Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
2003-01-20 04:13:46 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2003-01-20 04:13:46 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2003-01-20 04:13:46 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2003-01-20 04:13:46 +00:00
|
|
|
* 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
|
2007-07-21 23:32:33 +00:00
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2003-01-20 04:13:46 +00:00
|
|
|
*/
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
#include <grub/normal.h>
|
|
|
|
#include <grub/misc.h>
|
2004-09-10 20:31:55 +00:00
|
|
|
#include <grub/loader.h>
|
2004-09-18 13:42:05 +00:00
|
|
|
#include <grub/mm.h>
|
2008-08-07 23:48:13 +00:00
|
|
|
#include <grub/time.h>
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
#include <grub/env.h>
|
2009-01-31 09:15:43 +00:00
|
|
|
#include <grub/menu_viewer.h>
|
2009-05-02 Bean <bean123ch@gmail.com>
* conf/common.rmk (grub_script.tab.c): Change normal/parser.y to
script/sh/parser.y.
(pkglib_MODULES): Add normal.mod and sh.mod.
(normal_SOURCES): New variable.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
(sh_mod_SOURCES): Likewise.
(sh_mod_CFLAGS): Likewise.
(sh_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (normal/lexer.c_DEPENDENCIES): Changed to
script/sh/lexer.c_DEPENDENCIES.
(kernel_img_SOURCES): Remove kern/rescue.c, and kern/reader.c,
kern/rescue_reader.c and kern/rescue_parser.c.
(kernel_img_HEADERS): Remove rescue.h, add reader.h.
(grub_emu_SOURCES): Change source files.
(pkglib_MODULES): Remove normal.mod.
(normal_SOURCES): Removed.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1276.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/command.h (grub_command_execute): New inline function.
* include/grub/menu.h (grub_menu_entry): Removed commands field.
* include/grub/normal.h: Remove <grub/setjmp.h>.
(grub_fs_module_list): Moved to normal/autofs.c.
(grub_exit_env): Removed.
(grub_command_execute): Likewise.
(grub_normal_menu_addentry): Renamed to grub_menu_addentry, removed
parameter script.
(read_command_list): New function declaration.
(read_fs_list): Likewise.
* include/parser.h: Include <grub/reader.h>.
(grub_parser_split_cmdline): Change type of getline parameter.
(grub_parser): New structure.
(grub_parser_class): New variable.
(grub_parser_execute): New function declaration.
(grub_register_rescue_parser): Likewise.
(grub_parser_register): New inline function.
(grub_parser_unregister): Likewise.
(grub_parser_get_current): Likewise.
(grub_parser_set_current): Likewise.
* include/grub/reader.h: New file.
* kern/reader.c: Likewise.
* kern/rescue_parser.c: Likewise.
* kern/rescue_reader.c: Likewise.
* normal/autofs.c: Likewise.
* normal/dyncmd.c: Likewise.
* include/grub/rescue.h: Removed.
* normal/command.h: Likewise.
* include/grub/script.h: Moved to ...
* include/grub/script_sh.h: ... Moved here.
* normal/execute.c: Moved to ...
* script/sh/execute.c: ... Moved here.
* normal/function.c: Moved to ...
* script/sh/function.c: ... Moved here.
* normal/lexer.c: Moved to ...
* script/sh/lexer.c: ... Moved here.
* normal/parser.y: Moved to ...
* script/sh/parser.y: ... Moved here.
* normal/script.c: Moved to ...
* script/sh/script.c: ... Moved here.
* normal/main.c: Remove <grub/rescue.h> and <grub/script.h>, include
<grub/reader.h>.
(grub_exit_env): Removed.
(fs_module_list): Moved to normal/autofs.c.
(grub_file_getline): Don't handle comment here.
(free_menu): Skip removed field entry->commands.
(grub_normal_menu_addentry): Removed as grub_menu_entry, removed
script parameter.
(read_config_file): Removed nested parameter, change getline function.
(grub_enter_normal_mode): Removed.
(grub_dyncmd_dispatcher): Moved to normal/dyncmd.c.
(read_command_list): Likewise.
(autoload_fs_module): Moved to normal/autofs.c.
(read_fs_list): Likewise.
(reader_nested): New variable.
(grub_normal_execute): Run parser.sh to switch to sh parser.
(grub_cmd_rescue): Removed.
(cmd_normal): Removed.
(grub_cmd_normal): Unregister itself at the beginning. Don't register
rescue command.
(grub_cmdline_run): New function.
(grub_normal_reader_init): Likewise.
(grub_normal_read_line): Likewise.
(grub_env_write_pager): Likewise.
(cmdline): New variable.
(grub_normal_reader): Likewise.
(GRUB_MOD_INIT): Register normal reader and set as current, register
pager hook, register normal command with grub_register_command_prio,
so that it won't show up in command.lst.
(GRUB_MOD_FINI): Unregister normal reader, unhook pager, clear
grub_fs_autoload_hook.
* normal/menu.c: Remove <grub/script.h>, add <grub/command.h>.
(grub_menu_execute_entry): Replace grub_script_execute with
grub_parser_execute, change parameter to grub_command_execute.
* normal/menu_text.c: Remove <grub/script.h>.
* normal/menu_entry.c: Remove <grub/script.h>, add <grub/command.h>
and <grub/parser.h>.
(run): Change editor_getline to use new parser interface. Change
parameter to grub_command_execute.
* kern/main.c: Remove <grub/rescue.h>, include <grub/command.h>,
<grub/reader.h> and <grub/parser.h>.
(grub_load_normal_mode): Execute normal command.
(grub_main): Call grub_register_core_commands,
grub_register_rescue_parser and grub_register_rescue_reader, use
grub_reader_loop to enter input loop.
* kern/parser.c (grub_parser_spli_cmdline): Change type of getline
parameter.
(grub_parser_class): New variable.
(grub_parser_execute): New function.
* loader/i386/multiboot.c: Remove <grub/rescue.h>.
* loader/multiboot2.c: Likewise.
* loader/sparc64/ieee1275/linux.c: Likewise.
* util/grub-emu.c (read_command_list): New dummy function.
2009-05-02 19:49:34 +00:00
|
|
|
#include <grub/command.h>
|
2009-05-03 22:05:29 +00:00
|
|
|
#include <grub/parser.h>
|
2009-08-24 23:55:06 +00:00
|
|
|
#include <grub/auth.h>
|
2009-12-24 14:34:33 +00:00
|
|
|
#include <grub/i18n.h>
|
2009-12-26 15:39:16 +00:00
|
|
|
#include <grub/term.h>
|
2010-06-28 10:42:50 +00:00
|
|
|
#include <grub/script_sh.h>
|
2011-04-06 11:00:18 +00:00
|
|
|
#include <grub/gfxterm.h>
|
2011-04-08 10:12:02 +00:00
|
|
|
#include <grub/dl.h>
|
2009-12-24 14:34:33 +00:00
|
|
|
|
|
|
|
/* Time to delay after displaying an error message about a default/fallback
|
|
|
|
entry failing to boot. */
|
|
|
|
#define DEFAULT_ENTRY_ERROR_DELAY_MS 2500
|
|
|
|
|
2009-12-26 15:39:16 +00:00
|
|
|
grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu,
|
|
|
|
int nested) = NULL;
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2013-11-28 02:27:13 +00:00
|
|
|
enum timeout_style {
|
|
|
|
TIMEOUT_STYLE_MENU,
|
|
|
|
TIMEOUT_STYLE_COUNTDOWN,
|
|
|
|
TIMEOUT_STYLE_HIDDEN
|
|
|
|
};
|
|
|
|
|
|
|
|
struct timeout_style_name {
|
|
|
|
const char *name;
|
|
|
|
enum timeout_style style;
|
|
|
|
} timeout_style_names[] = {
|
|
|
|
{"menu", TIMEOUT_STYLE_MENU},
|
|
|
|
{"countdown", TIMEOUT_STYLE_COUNTDOWN},
|
|
|
|
{"hidden", TIMEOUT_STYLE_HIDDEN},
|
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
/* Wait until the user pushes any key so that the user
|
|
|
|
can see what happened. */
|
|
|
|
void
|
|
|
|
grub_wait_after_message (void)
|
|
|
|
{
|
2010-08-29 23:14:07 +00:00
|
|
|
grub_uint64_t endtime;
|
2010-03-15 10:49:27 +00:00
|
|
|
grub_xputs ("\n");
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_printf_ (N_("Press any key to continue..."));
|
2010-08-29 23:14:07 +00:00
|
|
|
grub_refresh ();
|
|
|
|
|
|
|
|
endtime = grub_get_time_ms () + 10000;
|
|
|
|
|
2012-02-18 18:59:01 +00:00
|
|
|
while (grub_get_time_ms () < endtime
|
|
|
|
&& grub_getkey_noblock () == GRUB_TERM_NO_KEY);
|
2010-08-29 23:14:07 +00:00
|
|
|
|
2010-03-15 10:49:27 +00:00
|
|
|
grub_xputs ("\n");
|
2009-12-24 14:34:33 +00:00
|
|
|
}
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
/* Get a menu entry by its index in the entry list. */
|
|
|
|
grub_menu_entry_t
|
|
|
|
grub_menu_get_entry (grub_menu_t menu, int no)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_menu_entry_t e;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
for (e = menu->entry_list; e && no > 0; e = e->next, no--)
|
|
|
|
;
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2013-11-28 02:27:13 +00:00
|
|
|
/* Get the index of a menu entry associated with a given hotkey, or -1. */
|
|
|
|
static int
|
|
|
|
get_entry_index_by_hotkey (grub_menu_t menu, int hotkey)
|
|
|
|
{
|
|
|
|
grub_menu_entry_t entry;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0, entry = menu->entry_list; i < menu->size;
|
|
|
|
i++, entry = entry->next)
|
|
|
|
if (entry->hotkey == hotkey)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the timeout style. If the variable "timeout_style" is not set or
|
|
|
|
invalid, default to TIMEOUT_STYLE_MENU. */
|
|
|
|
static enum timeout_style
|
|
|
|
get_timeout_style (void)
|
|
|
|
{
|
|
|
|
const char *val;
|
|
|
|
struct timeout_style_name *style_name;
|
|
|
|
|
|
|
|
val = grub_env_get ("timeout_style");
|
2013-12-03 16:11:00 +00:00
|
|
|
if (!val)
|
|
|
|
return TIMEOUT_STYLE_MENU;
|
|
|
|
|
|
|
|
for (style_name = timeout_style_names; style_name->name; style_name++)
|
|
|
|
if (grub_strcmp (style_name->name, val) == 0)
|
|
|
|
return style_name->style;
|
2013-11-28 02:27:13 +00:00
|
|
|
|
|
|
|
return TIMEOUT_STYLE_MENU;
|
|
|
|
}
|
|
|
|
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
/* Return the current timeout. If the variable "timeout" is not set or
|
|
|
|
invalid, return -1. */
|
2009-02-13 20:06:27 +00:00
|
|
|
int
|
|
|
|
grub_menu_get_timeout (void)
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
{
|
2011-11-11 19:34:37 +00:00
|
|
|
const char *val;
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
int timeout;
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
val = grub_env_get ("timeout");
|
|
|
|
if (! val)
|
|
|
|
return -1;
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
grub_error_push ();
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
timeout = (int) grub_strtoul (val, 0, 0);
|
|
|
|
|
|
|
|
/* If the value is invalid, unset the variable. */
|
|
|
|
if (grub_errno != GRUB_ERR_NONE)
|
|
|
|
{
|
|
|
|
grub_env_unset ("timeout");
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
timeout = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_error_pop ();
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set current timeout in the variable "timeout". */
|
2009-02-13 20:06:27 +00:00
|
|
|
void
|
|
|
|
grub_menu_set_timeout (int timeout)
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
{
|
|
|
|
/* Ignore TIMEOUT if it is zero, because it will be unset really soon. */
|
|
|
|
if (timeout > 0)
|
|
|
|
{
|
|
|
|
char buf[16];
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2009-12-29 09:04:06 +00:00
|
|
|
grub_snprintf (buf, sizeof (buf), "%d", timeout);
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
grub_env_set ("timeout", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
/* Get the first entry number from the value of the environment variable NAME,
|
2009-05-04 20:06:05 +00:00
|
|
|
which is a space-separated list of non-negative integers. The entry number
|
2009-02-13 20:06:27 +00:00
|
|
|
which is returned is stripped from the value of NAME. If no entry number
|
|
|
|
can be found, -1 is returned. */
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
static int
|
2009-02-13 20:06:27 +00:00
|
|
|
get_and_remove_first_entry_number (const char *name)
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
{
|
misc: Make grub_strtol() "end" pointers have safer const qualifiers
Currently the string functions grub_strtol(), grub_strtoul(), and
grub_strtoull() don't declare the "end" pointer in such a way as to
require the pointer itself or the character array to be immutable to the
implementation, nor does the C standard do so in its similar functions,
though it does require us not to change any of it.
The typical declarations of these functions follow this pattern:
long
strtol(const char * restrict nptr, char ** restrict endptr, int base);
Much of the reason for this is historic, and a discussion of that
follows below, after the explanation of this change. (GRUB currently
does not include the "restrict" qualifiers, and we name the arguments a
bit differently.)
The implementation is semantically required to treat the character array
as immutable, but such accidental modifications aren't stopped by the
compiler, and the semantics for both the callers and the implementation
of these functions are sometimes also helped by adding that requirement.
This patch changes these declarations to follow this pattern instead:
long
strtol(const char * restrict nptr,
const char ** const restrict endptr,
int base);
This means that if any modification to these functions accidentally
introduces either an errant modification to the underlying character
array, or an accidental assignment to endptr rather than *endptr, the
compiler should generate an error. (The two uses of "restrict" in this
case basically mean strtol() isn't allowed to modify the character array
by going through *endptr, and endptr isn't allowed to point inside the
array.)
It also means the typical use case changes to:
char *s = ...;
const char *end;
long l;
l = strtol(s, &end, 10);
Or even:
const char *p = str;
while (p && *p) {
long l = strtol(p, &p, 10);
...
}
This fixes 26 places where we discard our attempts at treating the data
safely by doing:
const char *p = str;
long l;
l = strtol(p, (char **)&ptr, 10);
It also adds 5 places where we do:
char *p = str;
while (p && *p) {
long l = strtol(p, (const char ** const)&p, 10);
...
/* more calls that need p not to be pointer-to-const */
}
While moderately distasteful, this is a better problem to have.
With one minor exception, I have tested that all of this compiles
without relevant warnings or errors, and that /much/ of it behaves
correctly, with gcc 9 using 'gcc -W -Wall -Wextra'. The one exception
is the changes in grub-core/osdep/aros/hostdisk.c , which I have no idea
how to build.
Because the C standard defined type-qualifiers in a way that can be
confusing, in the past there's been a slow but fairly regular stream of
churn within our patches, which add and remove the const qualifier in many
of the users of these functions. This change should help avoid that in
the future, and in order to help ensure this, I've added an explanation
in misc.h so that when someone does get a compiler warning about a type
error, they have the fix at hand.
The reason we don't have "const" in these calls in the standard is
purely anachronistic: C78 (de facto) did not have type qualifiers in the
syntax, and the "const" type qualifier was added for C89 (I think; it
may have been later). strtol() appears to date from 4.3BSD in 1986,
which means it could not be added to those functions in the standard
without breaking compatibility, which is usually avoided.
The syntax chosen for type qualifiers is what has led to the churn
regarding usage of const, and is especially confusing on string
functions due to the lack of a string type. Quoting from C99, the
syntax is:
declarator:
pointer[opt] direct-declarator
direct-declarator:
identifier
( declarator )
direct-declarator [ type-qualifier-list[opt] assignment-expression[opt] ]
...
direct-declarator [ type-qualifier-list[opt] * ]
...
pointer:
* type-qualifier-list[opt]
* type-qualifier-list[opt] pointer
type-qualifier-list:
type-qualifier
type-qualifier-list type-qualifier
...
type-qualifier:
const
restrict
volatile
So the examples go like:
const char foo; // immutable object
const char *foo; // mutable pointer to object
char * const foo; // immutable pointer to mutable object
const char * const foo; // immutable pointer to immutable object
const char const * const foo; // XXX extra const keyword in the middle
const char * const * const foo; // immutable pointer to immutable
// pointer to immutable object
const char ** const foo; // immutable pointer to mutable pointer
// to immutable object
Making const left-associative for * and right-associative for everything
else may not have been the best choice ever, but here we are, and the
inevitable result is people using trying to use const (as they should!),
putting it at the wrong place, fighting with the compiler for a bit, and
then either removing it or typecasting something in a bad way. I won't
go into describing restrict, but its syntax has exactly the same issue
as with const.
Anyway, the last example above actually represents the *behavior* that's
required of strtol()-like functions, so that's our choice for the "end"
pointer.
Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2020-02-21 21:39:33 +00:00
|
|
|
const char *val, *tail;
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
int entry;
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
val = grub_env_get (name);
|
|
|
|
if (! val)
|
|
|
|
return -1;
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
grub_error_push ();
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
entry = (int) grub_strtoul (val, &tail, 0);
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
if (grub_errno == GRUB_ERR_NONE)
|
|
|
|
{
|
|
|
|
/* Skip whitespace to find the next digit. */
|
|
|
|
while (*tail && grub_isspace (*tail))
|
|
|
|
tail++;
|
|
|
|
grub_env_set (name, tail);
|
|
|
|
}
|
|
|
|
else
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
{
|
2009-02-13 20:06:27 +00:00
|
|
|
grub_env_unset (name);
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
entry = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_error_pop ();
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2006-05-07 Yoshinori K. Okuji <okuji@enbug.org>
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
2006-05-07 18:28:24 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2004-09-10 20:31:55 +00:00
|
|
|
/* Run a menu entry. */
|
2011-01-10 22:27:58 +00:00
|
|
|
static void
|
|
|
|
grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot)
|
2004-09-10 20:31:55 +00:00
|
|
|
{
|
2009-08-24 23:55:06 +00:00
|
|
|
grub_err_t err = GRUB_ERR_NONE;
|
2010-09-20 15:46:35 +00:00
|
|
|
int errs_before;
|
2011-01-12 10:52:51 +00:00
|
|
|
grub_menu_t menu = NULL;
|
2011-01-10 22:27:58 +00:00
|
|
|
char *optr, *buf, *oldchosen = NULL, *olddefault = NULL;
|
|
|
|
const char *ptr, *chosen, *def;
|
|
|
|
grub_size_t sz = 0;
|
2009-08-24 23:55:06 +00:00
|
|
|
|
|
|
|
if (entry->restricted)
|
|
|
|
err = grub_auth_check_authentication (entry->users);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-20 15:46:35 +00:00
|
|
|
errs_before = grub_err_printed_errors;
|
|
|
|
|
2011-01-10 22:27:58 +00:00
|
|
|
chosen = grub_env_get ("chosen");
|
|
|
|
def = grub_env_get ("default");
|
|
|
|
|
2010-09-20 22:47:49 +00:00
|
|
|
if (entry->submenu)
|
|
|
|
{
|
|
|
|
grub_env_context_open ();
|
|
|
|
menu = grub_zalloc (sizeof (*menu));
|
|
|
|
if (! menu)
|
|
|
|
return;
|
|
|
|
grub_env_set_menu (menu);
|
2011-01-10 22:27:58 +00:00
|
|
|
if (auto_boot)
|
|
|
|
grub_env_set ("timeout", "0");
|
2010-09-20 22:47:49 +00:00
|
|
|
}
|
|
|
|
|
2012-03-04 13:55:13 +00:00
|
|
|
for (ptr = entry->id; *ptr; ptr++)
|
2011-01-10 22:27:58 +00:00
|
|
|
sz += (*ptr == '>') ? 2 : 1;
|
|
|
|
if (chosen)
|
|
|
|
{
|
|
|
|
oldchosen = grub_strdup (chosen);
|
|
|
|
if (!oldchosen)
|
|
|
|
grub_print_error ();
|
|
|
|
}
|
|
|
|
if (def)
|
|
|
|
{
|
|
|
|
olddefault = grub_strdup (def);
|
|
|
|
if (!olddefault)
|
|
|
|
grub_print_error ();
|
|
|
|
}
|
|
|
|
sz++;
|
|
|
|
if (chosen)
|
|
|
|
sz += grub_strlen (chosen);
|
|
|
|
sz++;
|
|
|
|
buf = grub_malloc (sz);
|
|
|
|
if (!buf)
|
|
|
|
grub_print_error ();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
optr = buf;
|
|
|
|
if (chosen)
|
|
|
|
{
|
|
|
|
optr = grub_stpcpy (optr, chosen);
|
|
|
|
*optr++ = '>';
|
|
|
|
}
|
2012-03-04 13:55:13 +00:00
|
|
|
for (ptr = entry->id; *ptr; ptr++)
|
2011-01-10 22:27:58 +00:00
|
|
|
{
|
|
|
|
if (*ptr == '>')
|
|
|
|
*optr++ = '>';
|
|
|
|
*optr++ = *ptr;
|
|
|
|
}
|
|
|
|
*optr = 0;
|
|
|
|
grub_env_set ("chosen", buf);
|
|
|
|
grub_env_export ("chosen");
|
|
|
|
grub_free (buf);
|
|
|
|
}
|
2011-07-25 05:48:19 +00:00
|
|
|
|
|
|
|
for (ptr = def; ptr && *ptr; ptr++)
|
2011-01-10 22:27:58 +00:00
|
|
|
{
|
|
|
|
if (ptr[0] == '>' && ptr[1] == '>')
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ptr[0] == '>')
|
|
|
|
break;
|
|
|
|
}
|
2011-07-25 05:48:19 +00:00
|
|
|
|
|
|
|
if (ptr && ptr[0] && ptr[1])
|
2011-01-10 22:27:58 +00:00
|
|
|
grub_env_set ("default", ptr + 1);
|
|
|
|
else
|
|
|
|
grub_env_unset ("default");
|
2011-07-25 05:48:19 +00:00
|
|
|
|
2013-06-07 16:36:42 +00:00
|
|
|
grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args);
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2010-09-20 15:46:35 +00:00
|
|
|
if (errs_before != grub_err_printed_errors)
|
|
|
|
grub_wait_after_message ();
|
|
|
|
|
2013-03-25 09:32:06 +00:00
|
|
|
errs_before = grub_err_printed_errors;
|
|
|
|
|
2004-09-10 20:31:55 +00:00
|
|
|
if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
|
|
|
|
/* Implicit execution of boot, only if something is loaded. */
|
2009-05-02 Bean <bean123ch@gmail.com>
* conf/common.rmk (grub_script.tab.c): Change normal/parser.y to
script/sh/parser.y.
(pkglib_MODULES): Add normal.mod and sh.mod.
(normal_SOURCES): New variable.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
(sh_mod_SOURCES): Likewise.
(sh_mod_CFLAGS): Likewise.
(sh_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (normal/lexer.c_DEPENDENCIES): Changed to
script/sh/lexer.c_DEPENDENCIES.
(kernel_img_SOURCES): Remove kern/rescue.c, and kern/reader.c,
kern/rescue_reader.c and kern/rescue_parser.c.
(kernel_img_HEADERS): Remove rescue.h, add reader.h.
(grub_emu_SOURCES): Change source files.
(pkglib_MODULES): Remove normal.mod.
(normal_SOURCES): Removed.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1276.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/command.h (grub_command_execute): New inline function.
* include/grub/menu.h (grub_menu_entry): Removed commands field.
* include/grub/normal.h: Remove <grub/setjmp.h>.
(grub_fs_module_list): Moved to normal/autofs.c.
(grub_exit_env): Removed.
(grub_command_execute): Likewise.
(grub_normal_menu_addentry): Renamed to grub_menu_addentry, removed
parameter script.
(read_command_list): New function declaration.
(read_fs_list): Likewise.
* include/parser.h: Include <grub/reader.h>.
(grub_parser_split_cmdline): Change type of getline parameter.
(grub_parser): New structure.
(grub_parser_class): New variable.
(grub_parser_execute): New function declaration.
(grub_register_rescue_parser): Likewise.
(grub_parser_register): New inline function.
(grub_parser_unregister): Likewise.
(grub_parser_get_current): Likewise.
(grub_parser_set_current): Likewise.
* include/grub/reader.h: New file.
* kern/reader.c: Likewise.
* kern/rescue_parser.c: Likewise.
* kern/rescue_reader.c: Likewise.
* normal/autofs.c: Likewise.
* normal/dyncmd.c: Likewise.
* include/grub/rescue.h: Removed.
* normal/command.h: Likewise.
* include/grub/script.h: Moved to ...
* include/grub/script_sh.h: ... Moved here.
* normal/execute.c: Moved to ...
* script/sh/execute.c: ... Moved here.
* normal/function.c: Moved to ...
* script/sh/function.c: ... Moved here.
* normal/lexer.c: Moved to ...
* script/sh/lexer.c: ... Moved here.
* normal/parser.y: Moved to ...
* script/sh/parser.y: ... Moved here.
* normal/script.c: Moved to ...
* script/sh/script.c: ... Moved here.
* normal/main.c: Remove <grub/rescue.h> and <grub/script.h>, include
<grub/reader.h>.
(grub_exit_env): Removed.
(fs_module_list): Moved to normal/autofs.c.
(grub_file_getline): Don't handle comment here.
(free_menu): Skip removed field entry->commands.
(grub_normal_menu_addentry): Removed as grub_menu_entry, removed
script parameter.
(read_config_file): Removed nested parameter, change getline function.
(grub_enter_normal_mode): Removed.
(grub_dyncmd_dispatcher): Moved to normal/dyncmd.c.
(read_command_list): Likewise.
(autoload_fs_module): Moved to normal/autofs.c.
(read_fs_list): Likewise.
(reader_nested): New variable.
(grub_normal_execute): Run parser.sh to switch to sh parser.
(grub_cmd_rescue): Removed.
(cmd_normal): Removed.
(grub_cmd_normal): Unregister itself at the beginning. Don't register
rescue command.
(grub_cmdline_run): New function.
(grub_normal_reader_init): Likewise.
(grub_normal_read_line): Likewise.
(grub_env_write_pager): Likewise.
(cmdline): New variable.
(grub_normal_reader): Likewise.
(GRUB_MOD_INIT): Register normal reader and set as current, register
pager hook, register normal command with grub_register_command_prio,
so that it won't show up in command.lst.
(GRUB_MOD_FINI): Unregister normal reader, unhook pager, clear
grub_fs_autoload_hook.
* normal/menu.c: Remove <grub/script.h>, add <grub/command.h>.
(grub_menu_execute_entry): Replace grub_script_execute with
grub_parser_execute, change parameter to grub_command_execute.
* normal/menu_text.c: Remove <grub/script.h>.
* normal/menu_entry.c: Remove <grub/script.h>, add <grub/command.h>
and <grub/parser.h>.
(run): Change editor_getline to use new parser interface. Change
parameter to grub_command_execute.
* kern/main.c: Remove <grub/rescue.h>, include <grub/command.h>,
<grub/reader.h> and <grub/parser.h>.
(grub_load_normal_mode): Execute normal command.
(grub_main): Call grub_register_core_commands,
grub_register_rescue_parser and grub_register_rescue_reader, use
grub_reader_loop to enter input loop.
* kern/parser.c (grub_parser_spli_cmdline): Change type of getline
parameter.
(grub_parser_class): New variable.
(grub_parser_execute): New function.
* loader/i386/multiboot.c: Remove <grub/rescue.h>.
* loader/multiboot2.c: Likewise.
* loader/sparc64/ieee1275/linux.c: Likewise.
* util/grub-emu.c (read_command_list): New dummy function.
2009-05-02 19:49:34 +00:00
|
|
|
grub_command_execute ("boot", 0, 0);
|
2010-09-20 22:47:49 +00:00
|
|
|
|
2013-03-25 09:32:06 +00:00
|
|
|
if (errs_before != grub_err_printed_errors)
|
|
|
|
grub_wait_after_message ();
|
|
|
|
|
2010-09-20 22:47:49 +00:00
|
|
|
if (entry->submenu)
|
|
|
|
{
|
|
|
|
if (menu && menu->size)
|
|
|
|
{
|
2011-01-10 22:27:58 +00:00
|
|
|
grub_show_menu (menu, 1, auto_boot);
|
2010-09-20 22:47:49 +00:00
|
|
|
grub_normal_free_menu (menu);
|
|
|
|
}
|
|
|
|
grub_env_context_close ();
|
|
|
|
}
|
2011-01-10 22:27:58 +00:00
|
|
|
if (oldchosen)
|
|
|
|
grub_env_set ("chosen", oldchosen);
|
|
|
|
else
|
|
|
|
grub_env_unset ("chosen");
|
|
|
|
if (olddefault)
|
|
|
|
grub_env_set ("default", olddefault);
|
|
|
|
else
|
|
|
|
grub_env_unset ("default");
|
|
|
|
grub_env_unset ("timeout");
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
/* Execute ENTRY from the menu MENU, falling back to entries specified
|
|
|
|
in the environment variable "fallback" if it fails. CALLBACK is a
|
|
|
|
pointer to a struct of function pointers which are used to allow the
|
|
|
|
caller provide feedback to the user. */
|
2011-01-10 22:27:58 +00:00
|
|
|
static void
|
2009-02-13 20:06:27 +00:00
|
|
|
grub_menu_execute_with_fallback (grub_menu_t menu,
|
|
|
|
grub_menu_entry_t entry,
|
2011-01-10 22:27:58 +00:00
|
|
|
int autobooted,
|
2009-02-13 20:06:27 +00:00
|
|
|
grub_menu_execute_callback_t callback,
|
|
|
|
void *callback_data)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2009-02-13 20:06:27 +00:00
|
|
|
int fallback_entry;
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
callback->notify_booting (entry, callback_data);
|
2004-09-10 20:31:55 +00:00
|
|
|
|
2011-01-10 22:27:58 +00:00
|
|
|
grub_menu_execute_entry (entry, 1);
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
/* Deal with fallback entries. */
|
|
|
|
while ((fallback_entry = get_and_remove_first_entry_number ("fallback"))
|
|
|
|
>= 0)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
2004-09-10 20:31:55 +00:00
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
entry = grub_menu_get_entry (menu, fallback_entry);
|
|
|
|
callback->notify_fallback (entry, callback_data);
|
2011-01-10 22:27:58 +00:00
|
|
|
grub_menu_execute_entry (entry, 1);
|
2009-02-13 20:06:27 +00:00
|
|
|
/* If the function call to execute the entry returns at all, then this is
|
|
|
|
taken to indicate a boot failure. For menu entries that do something
|
|
|
|
other than actually boot an operating system, this could assume
|
|
|
|
incorrectly that something failed. */
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2011-01-10 22:27:58 +00:00
|
|
|
if (!autobooted)
|
|
|
|
callback->notify_failure (callback_data);
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2009-11-20 13:45:33 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
static struct grub_menu_viewer *viewers;
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_set_chosen_entry (int entry)
|
|
|
|
{
|
|
|
|
struct grub_menu_viewer *cur;
|
|
|
|
for (cur = viewers; cur; cur = cur->next)
|
|
|
|
cur->set_chosen_entry (entry, cur->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_print_timeout (int timeout)
|
|
|
|
{
|
|
|
|
struct grub_menu_viewer *cur;
|
|
|
|
for (cur = viewers; cur; cur = cur->next)
|
|
|
|
cur->print_timeout (timeout, cur->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_fini (void)
|
|
|
|
{
|
|
|
|
struct grub_menu_viewer *cur, *next;
|
|
|
|
for (cur = viewers; cur; cur = next)
|
|
|
|
{
|
|
|
|
next = cur->next;
|
|
|
|
cur->fini (cur->data);
|
|
|
|
grub_free (cur);
|
|
|
|
}
|
|
|
|
viewers = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_init (int entry, grub_menu_t menu, int nested)
|
|
|
|
{
|
2009-12-26 15:39:16 +00:00
|
|
|
struct grub_term_output *term;
|
2011-04-06 11:00:18 +00:00
|
|
|
int gfxmenu = 0;
|
2009-12-26 15:39:16 +00:00
|
|
|
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
2012-05-21 20:17:11 +00:00
|
|
|
if (term->fullscreen)
|
2009-12-26 15:39:16 +00:00
|
|
|
{
|
2011-04-06 11:00:18 +00:00
|
|
|
if (grub_env_get ("theme"))
|
|
|
|
{
|
|
|
|
if (!grub_gfxmenu_try_hook)
|
|
|
|
{
|
|
|
|
grub_dl_load ("gfxmenu");
|
|
|
|
grub_print_error ();
|
|
|
|
}
|
|
|
|
if (grub_gfxmenu_try_hook)
|
|
|
|
{
|
|
|
|
grub_err_t err;
|
|
|
|
err = grub_gfxmenu_try_hook (entry, menu, nested);
|
|
|
|
if(!err)
|
|
|
|
{
|
|
|
|
gfxmenu = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-02-12 14:25:25 +00:00
|
|
|
grub_error (GRUB_ERR_BAD_MODULE,
|
|
|
|
N_("module `%s' isn't loaded"),
|
|
|
|
"gfxmenu");
|
2011-04-06 11:00:18 +00:00
|
|
|
grub_print_error ();
|
|
|
|
grub_wait_after_message ();
|
|
|
|
}
|
2009-12-26 15:39:16 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
2012-05-21 20:17:11 +00:00
|
|
|
term->fullscreen ();
|
2011-04-06 11:00:18 +00:00
|
|
|
break;
|
2009-12-26 15:39:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 11:00:18 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
|
|
|
grub_err_t err;
|
|
|
|
|
|
|
|
if (grub_strcmp (term->name, "gfxterm") == 0 && gfxmenu)
|
2011-12-25 16:41:55 +00:00
|
|
|
continue;
|
2011-04-06 11:00:18 +00:00
|
|
|
|
2009-12-26 15:39:16 +00:00
|
|
|
err = grub_menu_try_text (term, entry, menu, nested);
|
|
|
|
if(!err)
|
|
|
|
continue;
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
}
|
2009-12-24 14:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_timeout (void)
|
|
|
|
{
|
|
|
|
struct grub_menu_viewer *cur;
|
|
|
|
for (cur = viewers; cur; cur = cur->next)
|
|
|
|
cur->clear_timeout (cur->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_menu_register_viewer (struct grub_menu_viewer *viewer)
|
|
|
|
{
|
|
|
|
viewer->next = viewers;
|
|
|
|
viewers = viewer;
|
|
|
|
}
|
|
|
|
|
2011-01-10 22:27:58 +00:00
|
|
|
static int
|
2012-03-04 13:55:13 +00:00
|
|
|
menuentry_eq (const char *id, const char *spec)
|
2011-01-10 22:27:58 +00:00
|
|
|
{
|
|
|
|
const char *ptr1, *ptr2;
|
2012-03-04 13:55:13 +00:00
|
|
|
ptr1 = id;
|
2011-01-10 22:27:58 +00:00
|
|
|
ptr2 = spec;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
|
|
|
|
return 1;
|
|
|
|
if (*ptr2 == '>' && ptr2[1] != '>')
|
|
|
|
return 0;
|
|
|
|
if (*ptr2 == '>')
|
|
|
|
ptr2++;
|
|
|
|
if (*ptr1 != *ptr2)
|
|
|
|
return 0;
|
|
|
|
if (*ptr1 == 0)
|
|
|
|
return 1;
|
|
|
|
ptr1++;
|
|
|
|
ptr2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-20 13:45:33 +00:00
|
|
|
/* Get the entry number from the variable NAME. */
|
|
|
|
static int
|
|
|
|
get_entry_number (grub_menu_t menu, const char *name)
|
|
|
|
{
|
2011-01-10 22:27:58 +00:00
|
|
|
const char *val;
|
2009-11-20 13:45:33 +00:00
|
|
|
int entry;
|
|
|
|
|
|
|
|
val = grub_env_get (name);
|
|
|
|
if (! val)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
grub_error_push ();
|
|
|
|
|
|
|
|
entry = (int) grub_strtoul (val, 0, 0);
|
|
|
|
|
|
|
|
if (grub_errno == GRUB_ERR_BAD_NUMBER)
|
|
|
|
{
|
|
|
|
/* See if the variable matches the title of a menu entry. */
|
|
|
|
grub_menu_entry_t e = menu->entry_list;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
|
|
|
for (i = 0; e; i++)
|
|
|
|
{
|
2012-03-04 13:55:13 +00:00
|
|
|
if (menuentry_eq (e->title, val)
|
|
|
|
|| menuentry_eq (e->id, val))
|
2009-11-20 13:45:33 +00:00
|
|
|
{
|
|
|
|
entry = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! e)
|
|
|
|
entry = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (grub_errno != GRUB_ERR_NONE)
|
|
|
|
{
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
entry = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_error_pop ();
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2013-11-28 02:27:13 +00:00
|
|
|
/* Check whether a second has elapsed since the last tick. If so, adjust
|
|
|
|
the timer and return 1; otherwise, return 0. */
|
|
|
|
static int
|
|
|
|
has_second_elapsed (grub_uint64_t *saved_time)
|
|
|
|
{
|
|
|
|
grub_uint64_t current_time;
|
|
|
|
|
|
|
|
current_time = grub_get_time_ms ();
|
|
|
|
if (current_time - *saved_time >= 1000)
|
|
|
|
{
|
|
|
|
*saved_time = current_time;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_countdown (struct grub_term_coordinate *pos, int n)
|
|
|
|
{
|
|
|
|
grub_term_restore_pos (pos);
|
|
|
|
/* NOTE: Do not remove the trailing space characters.
|
|
|
|
They are required to clear the line. */
|
|
|
|
grub_printf ("%d ", n);
|
|
|
|
grub_refresh ();
|
|
|
|
}
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
#define GRUB_MENU_PAGE_SIZE 10
|
|
|
|
|
|
|
|
/* Show the menu and handle menu entry selection. Returns the menu entry
|
|
|
|
index that should be executed or -1 if no entry should be executed (e.g.,
|
|
|
|
Esc pressed to exit a sub-menu or switching menu viewers).
|
|
|
|
If the return value is not -1, then *AUTO_BOOT is nonzero iff the menu
|
|
|
|
entry to be executed is a result of an automatic default selection because
|
|
|
|
of the timeout. */
|
|
|
|
static int
|
|
|
|
run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
|
|
|
{
|
|
|
|
grub_uint64_t saved_time;
|
|
|
|
int default_entry, current_entry;
|
|
|
|
int timeout;
|
2013-11-28 02:27:13 +00:00
|
|
|
enum timeout_style timeout_style;
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2009-12-26 00:49:57 +00:00
|
|
|
default_entry = get_entry_number (menu, "default");
|
2009-12-24 14:34:33 +00:00
|
|
|
|
|
|
|
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
|
|
|
|
the first entry. */
|
|
|
|
if (default_entry < 0 || default_entry >= menu->size)
|
|
|
|
default_entry = 0;
|
|
|
|
|
2013-11-28 02:27:13 +00:00
|
|
|
timeout = grub_menu_get_timeout ();
|
|
|
|
if (timeout < 0)
|
|
|
|
/* If there is no timeout, the "countdown" and "hidden" styles result in
|
|
|
|
the system doing nothing and providing no or very little indication
|
|
|
|
why. Technically this is what the user asked for, but it's not very
|
|
|
|
useful and likely to be a source of confusion, so we disallow this. */
|
|
|
|
grub_env_unset ("timeout_style");
|
|
|
|
|
|
|
|
timeout_style = get_timeout_style ();
|
|
|
|
|
|
|
|
if (timeout_style == TIMEOUT_STYLE_COUNTDOWN
|
|
|
|
|| timeout_style == TIMEOUT_STYLE_HIDDEN)
|
|
|
|
{
|
|
|
|
static struct grub_term_coordinate *pos;
|
|
|
|
int entry = -1;
|
|
|
|
|
|
|
|
if (timeout_style == TIMEOUT_STYLE_COUNTDOWN && timeout)
|
|
|
|
{
|
|
|
|
pos = grub_term_save_pos ();
|
|
|
|
print_countdown (pos, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enter interruptible sleep until Escape or a menu hotkey is pressed,
|
|
|
|
or the timeout expires. */
|
|
|
|
saved_time = grub_get_time_ms ();
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int key;
|
|
|
|
|
|
|
|
key = grub_getkey_noblock ();
|
|
|
|
if (key != GRUB_TERM_NO_KEY)
|
|
|
|
{
|
|
|
|
entry = get_entry_index_by_hotkey (menu, key);
|
|
|
|
if (entry >= 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (key == GRUB_TERM_ESC)
|
|
|
|
{
|
|
|
|
timeout = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeout > 0 && has_second_elapsed (&saved_time))
|
|
|
|
{
|
|
|
|
timeout--;
|
|
|
|
if (timeout_style == TIMEOUT_STYLE_COUNTDOWN)
|
|
|
|
print_countdown (pos, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeout == 0)
|
|
|
|
/* We will fall through to auto-booting the default entry. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_env_unset ("timeout");
|
|
|
|
grub_env_unset ("timeout_style");
|
|
|
|
if (entry >= 0)
|
|
|
|
{
|
|
|
|
*auto_boot = 0;
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
/* If timeout is 0, drawing is pointless (and ugly). */
|
2013-11-28 02:27:13 +00:00
|
|
|
if (timeout == 0)
|
2009-12-24 14:34:33 +00:00
|
|
|
{
|
|
|
|
*auto_boot = 1;
|
|
|
|
return default_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_entry = default_entry;
|
|
|
|
|
|
|
|
refresh:
|
|
|
|
menu_init (current_entry, menu, nested);
|
|
|
|
|
2013-05-04 11:43:07 +00:00
|
|
|
/* Initialize the time. */
|
|
|
|
saved_time = grub_get_time_ms ();
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
timeout = grub_menu_get_timeout ();
|
|
|
|
|
|
|
|
if (timeout > 0)
|
|
|
|
menu_print_timeout (timeout);
|
2010-01-06 00:42:21 +00:00
|
|
|
else
|
|
|
|
clear_timeout ();
|
2009-12-24 14:34:33 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
timeout = grub_menu_get_timeout ();
|
|
|
|
|
2009-12-25 15:28:31 +00:00
|
|
|
if (grub_normal_exit_level)
|
|
|
|
return -1;
|
|
|
|
|
2013-11-28 02:27:13 +00:00
|
|
|
if (timeout > 0 && has_second_elapsed (&saved_time))
|
2009-12-24 14:34:33 +00:00
|
|
|
{
|
2013-11-28 02:27:13 +00:00
|
|
|
timeout--;
|
|
|
|
grub_menu_set_timeout (timeout);
|
|
|
|
menu_print_timeout (timeout);
|
2009-12-24 14:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (timeout == 0)
|
|
|
|
{
|
|
|
|
grub_env_unset ("timeout");
|
|
|
|
*auto_boot = 1;
|
|
|
|
menu_fini ();
|
|
|
|
return default_entry;
|
|
|
|
}
|
|
|
|
|
2012-02-18 18:59:01 +00:00
|
|
|
c = grub_getkey_noblock ();
|
2009-12-24 14:34:33 +00:00
|
|
|
|
normal/menu: Do not treat error values as key presses
Some terminals, like `grub-core/term/at_keyboard.c`, return `-1` in case
they are not ready yet.
if (! KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)))
return -1;
Currently, that is treated as a key press, and the menu time-out is
cancelled/cleared. This is unwanted, as the boot is stopped and the user
manually has to select a menu entry. Therefore, adapt the condition to
require the key value also to be greater than 0.
`GRUB_TERM_NO_KEY` is defined as 0, so the condition could be collapsed
to greater or equal than (≥) 0, but the compiler will probably do that
for us anyway, so keep the cases separate for clarity.
This is tested with coreboot, the GRUB default payload, and the
configuration file `grub.cfg` below.
For GRUB:
$ ./autogen.sh
$ ./configure --with-platform=coreboot
$ make -j`nproc`
$ make default_payload.elf
For coreboot:
$ more grub.cfg
serial --unit 0 --speed 115200
set timeout=5
menuentry 'halt' {
halt
}
$ build/cbfstool build/coreboot.rom add-payload \
-f /dev/shm/grub/default_payload.elf -n fallback/payload -c lzma
$ build/cbfstool build/coreboot.rom add -f grub.cfg -n etc/grub.cfg -t raw
$ qemu-system-x86_64 --version
QEMU emulator version 3.1.0 (Debian 1:3.1+dfsg-2+b1)
Copyright (c) 2003-2018 Fabrice Bellard and the QEMU Project developers
$ qemu-system-x86_64 -M pc -bios build/coreboot.rom -serial stdio -nic none
Currently, the time-out is cancelled/cleared. With the commit, it is not.
With a small GRUB payload, this the problem is also reproducible on the
ASRock E350M1.
Link: http://lists.gnu.org/archive/html/grub-devel/2019-01/msg00037.html
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-02-05 16:29:13 +00:00
|
|
|
/* Negative values are returned on error. */
|
|
|
|
if ((c != GRUB_TERM_NO_KEY) && (c > 0))
|
2012-02-18 18:59:01 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
if (timeout >= 0)
|
|
|
|
{
|
|
|
|
grub_env_unset ("timeout");
|
|
|
|
grub_env_unset ("fallback");
|
|
|
|
clear_timeout ();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_KEY_HOME:
|
|
|
|
case GRUB_TERM_CTRL | 'a':
|
2009-12-24 14:34:33 +00:00
|
|
|
current_entry = 0;
|
|
|
|
menu_set_chosen_entry (current_entry);
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_KEY_END:
|
|
|
|
case GRUB_TERM_CTRL | 'e':
|
2009-12-24 14:34:33 +00:00
|
|
|
current_entry = menu->size - 1;
|
|
|
|
menu_set_chosen_entry (current_entry);
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_KEY_UP:
|
|
|
|
case GRUB_TERM_CTRL | 'p':
|
2009-12-24 14:34:33 +00:00
|
|
|
case '^':
|
2009-12-25 00:13:21 +00:00
|
|
|
if (current_entry > 0)
|
|
|
|
current_entry--;
|
2009-12-24 14:34:33 +00:00
|
|
|
menu_set_chosen_entry (current_entry);
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'n':
|
|
|
|
case GRUB_TERM_KEY_DOWN:
|
2009-12-24 14:34:33 +00:00
|
|
|
case 'v':
|
2009-12-25 00:13:21 +00:00
|
|
|
if (current_entry < menu->size - 1)
|
|
|
|
current_entry++;
|
2009-12-24 14:34:33 +00:00
|
|
|
menu_set_chosen_entry (current_entry);
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'g':
|
|
|
|
case GRUB_TERM_KEY_PPAGE:
|
2009-12-24 14:34:33 +00:00
|
|
|
if (current_entry < GRUB_MENU_PAGE_SIZE)
|
|
|
|
current_entry = 0;
|
|
|
|
else
|
|
|
|
current_entry -= GRUB_MENU_PAGE_SIZE;
|
|
|
|
menu_set_chosen_entry (current_entry);
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'c':
|
|
|
|
case GRUB_TERM_KEY_NPAGE:
|
2009-12-24 14:34:33 +00:00
|
|
|
if (current_entry + GRUB_MENU_PAGE_SIZE < menu->size)
|
|
|
|
current_entry += GRUB_MENU_PAGE_SIZE;
|
2009-12-25 00:13:21 +00:00
|
|
|
else
|
|
|
|
current_entry = menu->size - 1;
|
2009-12-24 14:34:33 +00:00
|
|
|
menu_set_chosen_entry (current_entry);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_KEY_RIGHT:
|
|
|
|
case GRUB_TERM_CTRL | 'f':
|
2009-12-24 14:34:33 +00:00
|
|
|
menu_fini ();
|
|
|
|
*auto_boot = 0;
|
|
|
|
return current_entry;
|
|
|
|
|
2017-08-07 15:20:30 +00:00
|
|
|
case GRUB_TERM_ESC:
|
2009-12-24 14:34:33 +00:00
|
|
|
if (nested)
|
|
|
|
{
|
|
|
|
menu_fini ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
2009-12-25 03:12:29 +00:00
|
|
|
menu_fini ();
|
2014-09-21 16:51:09 +00:00
|
|
|
grub_cmdline_run (1, 0);
|
2009-12-24 14:34:33 +00:00
|
|
|
goto refresh;
|
|
|
|
|
|
|
|
case 'e':
|
2009-12-25 03:12:29 +00:00
|
|
|
menu_fini ();
|
2009-12-24 14:34:33 +00:00
|
|
|
{
|
|
|
|
grub_menu_entry_t e = grub_menu_get_entry (menu, current_entry);
|
|
|
|
if (e)
|
|
|
|
grub_menu_entry_run (e);
|
|
|
|
}
|
|
|
|
goto refresh;
|
|
|
|
|
|
|
|
default:
|
2009-12-29 22:01:12 +00:00
|
|
|
{
|
2013-11-28 02:27:13 +00:00
|
|
|
int entry;
|
|
|
|
|
|
|
|
entry = get_entry_index_by_hotkey (menu, c);
|
|
|
|
if (entry >= 0)
|
|
|
|
{
|
|
|
|
menu_fini ();
|
|
|
|
*auto_boot = 0;
|
|
|
|
return entry;
|
|
|
|
}
|
2009-12-29 22:01:12 +00:00
|
|
|
}
|
2009-12-24 14:34:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Never reach here. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback invoked immediately before a menu entry is executed. */
|
|
|
|
static void
|
|
|
|
notify_booting (grub_menu_entry_t entry,
|
|
|
|
void *userdata __attribute__((unused)))
|
|
|
|
{
|
|
|
|
grub_printf (" ");
|
2012-03-03 12:05:08 +00:00
|
|
|
grub_printf_ (N_("Booting `%s'"), entry->title);
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_printf ("\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback invoked when a default menu entry executed because of a timeout
|
|
|
|
has failed and an attempt will be made to execute the next fallback
|
|
|
|
entry, ENTRY. */
|
|
|
|
static void
|
|
|
|
notify_fallback (grub_menu_entry_t entry,
|
|
|
|
void *userdata __attribute__((unused)))
|
2009-11-20 13:45:33 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_printf ("\n ");
|
2012-03-03 12:05:08 +00:00
|
|
|
grub_printf_ (N_("Falling back to `%s'"), entry->title);
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_printf ("\n\n");
|
|
|
|
grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback invoked when a menu entry has failed and there is no remaining
|
|
|
|
fallback entry to attempt. */
|
|
|
|
static void
|
|
|
|
notify_execution_failure (void *userdata __attribute__((unused)))
|
|
|
|
{
|
|
|
|
if (grub_errno != GRUB_ERR_NONE)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
grub_printf ("\n ");
|
2010-01-20 02:50:36 +00:00
|
|
|
grub_printf_ (N_("Failed to boot both default and fallback entries.\n"));
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_wait_after_message ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callbacks used by the text menu to provide user feedback when menu entries
|
|
|
|
are executed. */
|
|
|
|
static struct grub_menu_execute_callback execution_callback =
|
|
|
|
{
|
|
|
|
.notify_booting = notify_booting,
|
|
|
|
.notify_fallback = notify_fallback,
|
|
|
|
.notify_failure = notify_execution_failure
|
|
|
|
};
|
|
|
|
|
|
|
|
static grub_err_t
|
2011-01-10 22:27:58 +00:00
|
|
|
show_menu (grub_menu_t menu, int nested, int autobooted)
|
2009-12-24 14:34:33 +00:00
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int boot_entry;
|
|
|
|
grub_menu_entry_t e;
|
|
|
|
int auto_boot;
|
|
|
|
|
|
|
|
boot_entry = run_menu (menu, nested, &auto_boot);
|
|
|
|
if (boot_entry < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
e = grub_menu_get_entry (menu, boot_entry);
|
|
|
|
if (! e)
|
|
|
|
continue; /* Menu is empty. */
|
|
|
|
|
|
|
|
grub_cls ();
|
|
|
|
|
|
|
|
if (auto_boot)
|
2011-01-10 22:27:58 +00:00
|
|
|
grub_menu_execute_with_fallback (menu, e, autobooted,
|
|
|
|
&execution_callback, 0);
|
2009-12-24 14:34:33 +00:00
|
|
|
else
|
2011-01-10 22:27:58 +00:00
|
|
|
grub_menu_execute_entry (e, 0);
|
|
|
|
if (autobooted)
|
|
|
|
break;
|
2009-12-24 14:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_err_t
|
2011-01-10 22:27:58 +00:00
|
|
|
grub_show_menu (grub_menu_t menu, int nested, int autoboot)
|
2009-12-24 14:34:33 +00:00
|
|
|
{
|
|
|
|
grub_err_t err1, err2;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2011-01-10 22:27:58 +00:00
|
|
|
err1 = show_menu (menu, nested, autoboot);
|
|
|
|
autoboot = 0;
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_print_error ();
|
|
|
|
|
2009-12-25 15:28:31 +00:00
|
|
|
if (grub_normal_exit_level)
|
|
|
|
break;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
err2 = grub_auth_check_authentication (NULL);
|
|
|
|
if (err2)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err1;
|
2009-11-20 13:45:33 +00:00
|
|
|
}
|