1/5 Multiple fallback entries
PATCH 1/1 1/5 Multiple fallback entries
This patch adds support for multiple fallback entries in grub.cfg.
I'll prepare the ChangeLog entry when the patch is approved to be committed.
The patch is against GRUB trunk revision 1964.
Regards,
Colin
=== modified file 'include/grub/normal.h'
grub/normal.h +14 -0
@@ -98,10 +98,24 @@extern struct grub_menu_viewer grub_normal_terminal_menu_viewer; +typedef struct grub_menu_execute_callback +{ +void (*notify_booting) (void *userdata,grub_menu_entry_t entry); +void (*notify_fallback) (void *userdata,grub_menu_entry_t entry); +void (*notify_failure) (void *userdata); +} +*grub_menu_execute_callback_t ; +void grub_enter_normal_mode (const char *config);void grub_normal_execute (const char *config,int nested); +void grub_menu_execute_with_fallback (grub_menu_t menu, +grub_menu_entry_t entry, +grub_menu_execute_callback_t callback, +void *callback_data);void grub_menu_entry_run (grub_menu_entry_t entry);void grub_menu_execute_entry (grub_menu_entry_t entry); +int grub_menu_get_timeout (void ); +void grub_menu_set_timeout (int timeout);void grub_cmdline_run (int nested);int grub_cmdline_get (const char *prompt,char cmdline[],unsigned max_len,int echo_char,int readline);
=== modified file 'normal/menu.c'
menu.c +117 -36
223 lines not on this page · raw message
Quoted 6 lines · Colin D Bennett
This patch adds support for multiple fallback entries in grub.cfg.
I'll prepare the ChangeLog entry when the patch is approved to be committed.
The patch is against GRUB trunk revision 1964.
What do you think if all text menu related would be moved to own file, like menu_text.c or so ? I think it will cleanup code nicely...
grub/normal.h line 105
Quoted 12 lines
=== modified file '
include/grub/normal.h'grub/normal.h +5
-0@@ -98,10 +98,24 @@extern struct grub_menu_viewer grub_normal_terminal_menu_viewer; +typedef struct grub_menu_execute_callback +{ + void (*notify_booting) (void *userdata, grub_menu_entry_t entry); + void (*notify_fallback) (void *userdata, grub_menu_entry_t entry); + void (*notify_failure) (void *userdata);
Usually pointer to userdata is last argument in list. Please use same term for it as in grub_menu_execute_with_fallback (you are free to pick new name if you see that it fits better).
Quoted 43 lines
grub/normal.h +9
-0+} +*grub_menu_execute_callback_t; +void grub_enter_normal_mode (const char *config);void grub_normal_execute (const char *config,int nested); +void grub_menu_execute_with_fallback (grub_menu_t menu, +grub_menu_entry_t entry, +grub_menu_execute_callback_t callback, +void *callback_data);void grub_menu_entry_run (grub_menu_entry_t entry);void grub_menu_execute_entry (grub_menu_entry_t entry); +int grub_menu_get_timeout (void ); +void grub_menu_set_timeout (int timeout);void grub_cmdline_run (int nested);int grub_cmdline_get (const char *prompt,char cmdline[],unsigned max_len,int echo_char,int readline);=== modified file '
normal/menu.c'menu.c +4
-4@@ -244,8 +244,8 @@/* Return the current timeout. If the variable "timeout" is not set or invalid, return -1. */ -static int -get_timeout (void ) +int +grub_menu_get_timeout (void ) {char *val;int timeout;@@ -272,8 +272,8 @@ }/* Set current timeout in the variable "timeout". */ -static void -set_timeout (int timeout) +void +grub_menu_set_timeout (int timeout) {/* Ignore TIMEOUT if it is zero, because it will be unset really soon. */ if (timeout >0 )
menu.c line 317
Quoted 7 lines
menu.c +4
-0@@ -311,6 +311,44 @@return entry; } +/* Get the first entry number from the variable NAME, which is a +space-separated list of nonnegative integers. The entry number which +is returned is stripped from the value of NAME. If no entry number can +be found, returns -1. */
We use term environment variable...
Quoted 14 lines
menu.c +14
-0+static int +get_and_remove_first_entry_number (const char *name) +{ +char *val; +char *tail; +int entry; + + val =grub_env_get (name); +if (! val) +return -1 ; + +grub_error_push (); + + entry = (int )grub_strtoul (val, &tail,0 );
...
menu.c line 635
Quoted 3 lines
menu.c +3
-0+ +/* Callbacks for grub_menu_execute_with_fallback() for the text menu. */ +
If you move these to new file, please replace this comment with new comments for every function.
menu.c line 648
Quoted 13 lines
menu.c +13
-0+static void +notify_booting (void *userdata __attribute__((unused)), +grub_menu_entry_t entry) +{ +grub_printf (" Booting \'%s\'\n\n" , entry->title); +} + +static void +notify_fallback (void *userdata __attribute__((unused)), +grub_menu_entry_t entry) +{ +grub_printf ("\n Falling back to \'%s\'\n\n" , entry->title); +grub_millisleep (2000 );
I think this delay should be generic part of the implementation and not specific to text menu. Or alternatively it needs to be documented that fallback callback function is supposed to wait for 2 secs...
Here is an updated patch based on Vesa's feedback. I will commit it in a few days if no one has any objections.
This patch is against GRUB trunk revision 1973.
Quoted 2 lines · On Sat, 31 Jan 2009 23:08:23 +0200 Vesa Jääskeläinen <[email protected]> wrote:
What do you think if all text menu related would be moved to own file, like
menu_text.cor so ? I think it will cleanup code nicely...
Agreed. It has been done.
Quoted 3 lines
Usually pointer to userdata is last argument in list. Please use same term for it as in
grub_menu_execute_with_fallback(you are free to pick new name if you see that it fits better).
The ‘userdata’ argument has been moved to the end of the argument list.
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+/* Get the first entry number from the variable NAME, which is a + space-separated list of nonnegative integers. The entry number which + is returned is stripped from the value of NAME. If no entry number can + be found, returns -1. */We use term environment variable...
Fixed.
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ +/* Callbacks for grub_menu_execute_with_fallback() for the text menu. */ +If you move these to new file, please replace this comment with new comments for every function.
Done.
Quoted 9 lines
Quoted 9 lines
(quoted diff) +9
-0+static void +notify_booting (void *userdata __attribute__((unused)), + grub_menu_entry_t entry) +{ + grub_printf (" Booting \'%s\'\n\n", entry->title); +} + +static void +notify_fallback (void *userdata __attribute__((unused)),
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ grub_menu_entry_t entry) +{ + grub_printf ("\n Falling back to \'%s\'\n\n", entry->title); + grub_millisleep (2000);I think this delay should be generic part of the implementation and not specific to text menu. Or alternatively it needs to be documented that fallback callback function is supposed to wait for 2 secs...
I just added a comment documenting the fact that the implementation of the callback should delay at least 2 sec before returning so that the user can see the message. I didn't just put the delay in the generic code because I thought the graphical menu, for instance, might want to do something during the delay like doing animation or something, or providing an OK button to dismiss the message before the delay has elapsed.
Regards,
Colin
=== modified file 'ChangeLog'
ChangeLog +63 -0
@@ -1,3 +1,66 @@ +2009-02-05 Colin D Bennett <[email protected]> + + Support multiple fallback entries, and provide an API to support + executing default+fallback menu entries. Renamed the `terminal' menu + viewer to `text'. + + * include/grub/normal.h (grub_normal_text_menu_viewer): New global + variable declaration. + (grub_menu_execute_callback): New structure declaration. + (grub_menu_execute_callback_t): New typedef. + (grub_menu_execute_with_fallback): New function declaration. + (grub_menu_get_timeout): Likewise. + (grub_menu_set_timeout): Likewise. + + * normal/main.c (GRUB_MOD_INIT(normal)): Refer to new variable name. + + * normal/menu.c (grub_wait_after_message): Moved to + `normal/menu_text.c'. + (draw_border): Likewise. + (print_message): Likewise. + (print_entry): Likewise. + (print_entries): Likewise. + (grub_menu_init_page): Likewise. + (get_entry_number): Likewise. + (print_timeout): Likewise. + (run_menu): Likewise. + (grub_menu_execute_entry): Likewise. + (show_text_menu): Likewise. + (get_and_remove_first_entry_number): New function. + (grub_menu_execute_with_fallback): Likewise. + (get_entry): Renamed to ... + (grub_menu_get_entry): .. this and made it global. + (get_timeout): Renamed to ... + (grub_menu_get_timeout): ... this and made it global. + (set_timeout): Renamed to ... + (grub_menu_set_timeout): ... this and made it global. + (grub_normal_terminal_menu_viewer): Renamed to ... + (grub_normal_text_menu_viewer): ... this. + + * normal/menu_text.c: New file. Extracted text-menu-specific code + from normal/menu.c. + + * conf/i386-coreboot.rmk (grub_emu_SOURCES): Add `normal/menu_text.c'. + (normal_mod_SOURCES): Likewise. + + * conf/i386-efi.rmk (grub_emu_SOURCES): Likewise. + (normal_mod_SOURCES): Likewise. + + * conf/i386-ieee1275.rmk (grub_emu_SOURCES): Likewise. + (normal_mod_SOURCES): Likewise. + + * conf/i386-pc.rmk, (grub_emu_SOURCES): Likewise. + (normal_mod_SOURCES): Likewise. + + * conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise. + (normal_mod_SOURCES): Likewise. + + * conf/sparc64-ieee1275.rmk (grub_emu_SOURCES): Likewise. + (normal_mod_SOURCES): Likewise. + + * conf/x86_64-efi.rmk (grub_emu_SOURCES): Likewise. + (normal_mod_SOURCES): Likewise. + 2009-02-04 Felix Zielcke <[email protected]> util/getroot.c (grub_util_get_grub_dev): Add support for /dev/mdNpN and
=== modified file 'conf/i386-coreboot.rmk'
i386-coreboot.rmk +2 -1
@@ -75,7 +75,7 @@ kern/loader.c kern/main.c kern/misc.c kern/parser.c \ grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ normal/arg.c normal/cmdline.c normal/command.c normal/function.c\ - normal/completion.c normal/main.c \ + normal/completion.c normal/main.c normal/menu_text.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ normal/misc.c normal/script.c \ normal/color.c \
@@ -123,6 +123,7 @@ normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/menu_text.c \ normal/color.c \ normal/menu_viewer.c normal/menu_entry.c \ normal/misc.c grub_script.tab.c \
=== modified file 'conf/i386-efi.rmk'
i386-efi.rmk +2 -0
@@ -54,6 +54,7 @@ normal/arg.c normal/cmdline.c normal/command.c normal/function.c\ normal/completion.c normal/context.c normal/main.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ + normal/menu_text.c \ normal/misc.c normal/script.c \ normal/color.c \ partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \
@@ -120,6 +121,7 @@ normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/menu_text.c \ normal/color.c \ normal/menu_viewer.c normal/menu_entry.c \ normal/misc.c grub_script.tab.c \
=== modified file 'conf/i386-ieee1275.rmk'
i386-ieee1275.rmk +2 -1
@@ -74,7 +74,7 @@ kern/loader.c kern/main.c kern/misc.c kern/parser.c \ grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ normal/arg.c normal/cmdline.c normal/command.c normal/function.c\ - normal/completion.c normal/main.c \ + normal/completion.c normal/main.c normal/menu_text.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ normal/misc.c normal/script.c \ normal/color.c \
@@ -113,6 +113,7 @@ normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/menu_text.c \ normal/color.c \ normal/menu_viewer.c normal/menu_entry.c \ normal/misc.c grub_script.tab.c \
=== modified file 'conf/i386-pc.rmk'
i386-pc.rmk +2 -0
@@ -130,6 +130,7 @@ normal/arg.c normal/cmdline.c normal/command.c normal/function.c\ normal/completion.c normal/main.c normal/color.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ + normal/menu_text.c \ normal/misc.c normal/script.c \ partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ partmap/acorn.c partmap/gpt.c \
@@ -203,6 +204,7 @@ normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/menu_text.c \ normal/color.c \ normal/menu_viewer.c normal/menu_entry.c \ normal/misc.c grub_script.tab.c \
=== modified file 'conf/powerpc-ieee1275.rmk'
powerpc-ieee1275.rmk +2 -0
@@ -58,6 +58,7 @@ normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/menu_text.c \ normal/menu_entry.c normal/menu_viewer.c normal/misc.c \ normal/script.c \ normal/color.c \
@@ -133,6 +134,7 @@ normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/menu_text.c \ normal/color.c \ normal/menu_viewer.c normal/menu_entry.c \ normal/misc.c grub_script.tab.c \
=== modified file 'conf/sparc64-ieee1275.rmk'
sparc64-ieee1275.rmk +2 -0
@@ -59,6 +59,7 @@ # normal/completion.c normal/context.c normal/execute.c \ # normal/function.c normal/lexer.c \ # normal/main.c normal/menu.c normal/menu_entry.c \ +# normal/menu_text.c \ # normal/menu_viewer.c normal/misc.c \ # partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ # partmap/acorn.c \
@@ -166,6 +167,7 @@ normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/menu_text.c \ normal/color.c \ normal/menu_viewer.c normal/menu_entry.c \ normal/misc.c grub_script.tab.c \
=== modified file 'conf/x86_64-efi.rmk'
x86_64-efi.rmk +2 -0
@@ -56,6 +56,7 @@ normal/arg.c normal/cmdline.c normal/command.c normal/function.c\ normal/completion.c normal/context.c normal/main.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ + normal/menu_text.c \ normal/misc.c normal/script.c \ normal/color.c \ partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \
@@ -122,6 +123,7 @@ normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/menu_text.c \ normal/color.c \ normal/menu_viewer.c normal/menu_entry.c \ normal/misc.c grub_script.tab.c \
=== modified file 'include/grub/normal.h'
grub/normal.h +28 -2
@@ -79,7 +79,7 @@/* The name of a module. Used for auto-loading. */ char *module_name; - +/* The next element. */ struct grub_command *next; };
@@ -96,12 +96,38 @@/* To exit from the normal mode. */ extern grub_jmp_buf grub_exit_env; -extern struct grub_menu_viewer grub_normal_terminal_menu_viewer; +extern struct grub_menu_viewer grub_normal_text_menu_viewer; + +/* Callback structure menu viewers can use to provide user feedback when +default entries are executed, possibly including fallback entries. */ +typedef struct grub_menu_execute_callback +{ +/* Called immediately before ENTRY is booted. */ +void (*notify_booting) (grub_menu_entry_t entry,void *userdata); + +/* Called when executing one entry has failed, and another entry, ENTRY, will +be executed as a fallback. The implementation of this function should +delay for a period of at least 2 seconds before returning in order to +allow the user time to read the information before it can be lost by +executing ENTRY. */ +void (*notify_fallback) (grub_menu_entry_t entry,void *userdata); + +/* Called when an entry has failed to execute and there is no remaining +fallback entry to attempt. */ +void (*notify_failure) (void *userdata); +} +*grub_menu_execute_callback_t ;void grub_enter_normal_mode (const char *config);void grub_normal_execute (const char *config,int nested); +void grub_menu_execute_with_fallback (grub_menu_t menu, +grub_menu_entry_t entry, +grub_menu_execute_callback_t callback, +void *callback_data);void grub_menu_entry_run (grub_menu_entry_t entry);void grub_menu_execute_entry (grub_menu_entry_t entry); +int grub_menu_get_timeout (void ); +void grub_menu_set_timeout (int timeout);void grub_cmdline_run (int nested);int grub_cmdline_get (const char *prompt,char cmdline[],unsigned max_len,int echo_char,int readline);
=== modified file 'normal/main.c'
main.c +1 -1
@@ -620,7 +620,7 @@if (mod)grub_dl_ref (mod); -grub_menu_viewer_register (&grub_normal_terminal_menu_viewer); +grub_menu_viewer_register (&grub_normal_text_menu_viewer);grub_set_history (GRUB_DEFAULT_HISTORY_SIZE );
=== modified file 'normal/menu.c'
menu.c +51 -506
616 lines not on this page · raw message
=== added file 'normal/menu_text.c'
menu_text.c +570 -0
570 lines not on this page · raw message
Committed, with a few improvement to error handling when executing menu entries.
Regards,
Colin