1 /* menu.c - General supporting functionality for menus. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/normal.h>
21 #include <grub/misc.h>
22 #include <grub/loader.h>
24 #include <grub/time.h>
26 #include <grub/menu_viewer.h>
27 #include <grub/command.h>
28 #include <grub/parser.h>
29 #include <grub/auth.h>
30 #include <grub/i18n.h>
31 #include <grub/term.h>
32 #include <grub/script_sh.h>
33 #include <grub/gfxterm.h>
36 #include <grub/extcmd.h>
37 #include <grub/ventoy.h>
38 #include "ventoy/ventoy_def.h"
40 int g_ventoy_menu_refresh
= 0;
41 int g_ventoy_memdisk_mode
= 0;
42 int g_ventoy_iso_raw
= 0;
43 int g_ventoy_grub2_mode
= 0;
44 int g_ventoy_wimboot_mode
= 0;
45 int g_ventoy_iso_uefi_drv
= 0;
46 int g_ventoy_last_entry
= -1;
47 int g_ventoy_suppress_esc
= 0;
48 int g_ventoy_suppress_esc_default
= 1;
49 int g_ventoy_menu_esc
= 0;
50 int g_ventoy_fn_mutex
= 0;
51 int g_ventoy_terminal_output
= 0;
53 #define VTOY_COMM_HOTKEY(cmdkey) \
54 if (0 == g_ventoy_fn_mutex) { \
55 cmdstr = grub_env_get(cmdkey); \
59 g_ventoy_fn_mutex = 1; \
60 grub_script_execute_sourcecode(cmdstr); \
61 g_ventoy_fn_mutex = 0; \
66 /* Time to delay after displaying an error message about a default/fallback
67 entry failing to boot. */
68 #define DEFAULT_ENTRY_ERROR_DELAY_MS 2500
70 grub_err_t (*grub_gfxmenu_try_hook
) (int entry
, grub_menu_t menu
,
75 TIMEOUT_STYLE_COUNTDOWN
,
79 struct timeout_style_name
{
81 enum timeout_style style
;
82 } timeout_style_names
[] = {
83 {"menu", TIMEOUT_STYLE_MENU
},
84 {"countdown", TIMEOUT_STYLE_COUNTDOWN
},
85 {"hidden", TIMEOUT_STYLE_HIDDEN
},
89 /* Wait until the user pushes any key so that the user
90 can see what happened. */
92 grub_wait_after_message (void)
94 grub_uint64_t endtime
;
96 grub_printf_ (N_("Press any key to continue..."));
99 endtime
= grub_get_time_ms () + 10000;
101 while (grub_get_time_ms () < endtime
102 && grub_getkey_noblock () == GRUB_TERM_NO_KEY
);
107 /* Get a menu entry by its index in the entry list. */
109 grub_menu_get_entry (grub_menu_t menu
, int no
)
113 for (e
= menu
->entry_list
; e
&& no
> 0; e
= e
->next
, no
--)
119 /* Get the index of a menu entry associated with a given hotkey, or -1. */
121 get_entry_index_by_hotkey (grub_menu_t menu
, int hotkey
)
123 grub_menu_entry_t entry
;
126 for (i
= 0, entry
= menu
->entry_list
; i
< menu
->size
;
127 i
++, entry
= entry
->next
)
128 if (entry
->hotkey
== hotkey
)
134 /* Return the timeout style. If the variable "timeout_style" is not set or
135 invalid, default to TIMEOUT_STYLE_MENU. */
136 static enum timeout_style
137 get_timeout_style (void)
140 struct timeout_style_name
*style_name
;
142 val
= grub_env_get ("timeout_style");
144 return TIMEOUT_STYLE_MENU
;
146 for (style_name
= timeout_style_names
; style_name
->name
; style_name
++)
147 if (grub_strcmp (style_name
->name
, val
) == 0)
148 return style_name
->style
;
150 return TIMEOUT_STYLE_MENU
;
153 /* Return the current timeout. If the variable "timeout" is not set or
154 invalid, return -1. */
156 grub_menu_get_timeout (void)
161 val
= grub_env_get ("timeout");
167 timeout
= (int) grub_strtoul (val
, 0, 0);
169 /* If the value is invalid, unset the variable. */
170 if (grub_errno
!= GRUB_ERR_NONE
)
172 grub_env_unset ("timeout");
173 grub_errno
= GRUB_ERR_NONE
;
182 /* Set current timeout in the variable "timeout". */
184 grub_menu_set_timeout (int timeout
)
186 /* Ignore TIMEOUT if it is zero, because it will be unset really soon. */
191 grub_snprintf (buf
, sizeof (buf
), "%d", timeout
);
192 grub_env_set ("timeout", buf
);
196 /* Get the first entry number from the value of the environment variable NAME,
197 which is a space-separated list of non-negative integers. The entry number
198 which is returned is stripped from the value of NAME. If no entry number
199 can be found, -1 is returned. */
201 get_and_remove_first_entry_number (const char *name
)
207 val
= grub_env_get (name
);
213 entry
= (int) grub_strtoul (val
, &tail
, 0);
215 if (grub_errno
== GRUB_ERR_NONE
)
217 /* Skip whitespace to find the next digit. */
218 while (*tail
&& grub_isspace (*tail
))
220 grub_env_set (name
, tail
);
224 grub_env_unset (name
);
225 grub_errno
= GRUB_ERR_NONE
;
234 /* Run a menu entry. */
236 grub_menu_execute_entry(grub_menu_entry_t entry
, int auto_boot
)
238 grub_err_t err
= GRUB_ERR_NONE
;
240 grub_menu_t menu
= NULL
;
241 char *optr
, *buf
, *oldchosen
= NULL
, *olddefault
= NULL
;
242 const char *ptr
, *chosen
, *def
;
245 if (entry
->restricted
)
246 err
= grub_auth_check_authentication (entry
->users
);
251 grub_errno
= GRUB_ERR_NONE
;
255 errs_before
= grub_err_printed_errors
;
257 chosen
= grub_env_get ("chosen");
258 def
= grub_env_get ("default");
262 grub_env_context_open ();
263 menu
= grub_zalloc (sizeof (*menu
));
266 grub_env_set_menu (menu
);
268 grub_env_set ("timeout", "0");
271 for (ptr
= entry
->id
; *ptr
; ptr
++)
272 sz
+= (*ptr
== '>') ? 2 : 1;
275 oldchosen
= grub_strdup (chosen
);
281 olddefault
= grub_strdup (def
);
287 sz
+= grub_strlen (chosen
);
289 buf
= grub_malloc (sz
);
297 optr
= grub_stpcpy (optr
, chosen
);
300 for (ptr
= entry
->id
; *ptr
; ptr
++)
307 grub_env_set ("chosen", buf
);
308 grub_env_export ("chosen");
312 for (ptr
= def
; ptr
&& *ptr
; ptr
++)
314 if (ptr
[0] == '>' && ptr
[1] == '>')
323 if (ptr
&& ptr
[0] && ptr
[1])
324 grub_env_set ("default", ptr
+ 1);
326 grub_env_unset ("default");
328 grub_script_execute_new_scope (entry
->sourcecode
, entry
->argc
, entry
->args
);
330 if (errs_before
!= grub_err_printed_errors
)
331 grub_wait_after_message ();
333 errs_before
= grub_err_printed_errors
;
335 if (grub_errno
== GRUB_ERR_NONE
&& grub_loader_is_loaded ())
336 /* Implicit execution of boot, only if something is loaded. */
337 grub_command_execute ("boot", 0, 0);
339 if (errs_before
!= grub_err_printed_errors
)
340 grub_wait_after_message ();
344 if (menu
&& menu
->size
)
346 grub_show_menu (menu
, 1, auto_boot
);
347 grub_normal_free_menu (menu
);
349 grub_env_context_close ();
352 grub_env_set ("chosen", oldchosen
);
354 grub_env_unset ("chosen");
356 grub_env_set ("default", olddefault
);
358 grub_env_unset ("default");
359 grub_env_unset ("timeout");
362 /* Execute ENTRY from the menu MENU, falling back to entries specified
363 in the environment variable "fallback" if it fails. CALLBACK is a
364 pointer to a struct of function pointers which are used to allow the
365 caller provide feedback to the user. */
367 grub_menu_execute_with_fallback (grub_menu_t menu
,
368 grub_menu_entry_t entry
,
370 grub_menu_execute_callback_t callback
,
375 callback
->notify_booting (entry
, callback_data
);
377 grub_menu_execute_entry (entry
, 1);
379 /* Deal with fallback entries. */
380 while ((fallback_entry
= get_and_remove_first_entry_number ("fallback"))
384 grub_errno
= GRUB_ERR_NONE
;
386 entry
= grub_menu_get_entry (menu
, fallback_entry
);
387 callback
->notify_fallback (entry
, callback_data
);
388 grub_menu_execute_entry (entry
, 1);
389 /* If the function call to execute the entry returns at all, then this is
390 taken to indicate a boot failure. For menu entries that do something
391 other than actually boot an operating system, this could assume
392 incorrectly that something failed. */
396 callback
->notify_failure (callback_data
);
399 static struct grub_menu_viewer
*viewers
;
401 int g_menu_update_mode
= 0;
402 int g_ventoy_tip_label_enable
= 0;
403 const char * g_ventoy_tip_msg1
= NULL
;
404 const char * g_ventoy_tip_msg2
= NULL
;
405 char g_ventoy_theme_path
[256] = {0};
406 static const char *g_ventoy_cur_img_path
= NULL
;
407 static void menu_set_chosen_tip(grub_menu_t menu
, int entry
)
412 grub_menu_entry_t e
= grub_menu_get_entry (menu
, entry
);
414 if (g_ventoy_theme_path
[0])
416 grub_env_set("theme", g_ventoy_theme_path
);
419 g_ventoy_tip_msg1
= g_ventoy_tip_msg2
= NULL
;
420 if (e
&& e
->id
&& grub_strncmp(e
->id
, "VID_", 4) == 0)
422 g_ventoy_theme_path
[0] = 0;
423 img
= (img_info
*)(void *)grub_strtoul(e
->id
+ 4, NULL
, 16);
426 g_ventoy_tip_msg1
= img
->tip1
;
427 g_ventoy_tip_msg2
= img
->tip2
;
428 g_ventoy_cur_img_path
= img
->path
;
431 else if (e
&& e
->id
&& grub_strncmp(e
->id
, "DIR_", 4) == 0)
433 g_ventoy_theme_path
[0] = 0;
434 for (i
= 0; i
< e
->argc
; i
++)
436 if (e
->args
[i
] && grub_strncmp(e
->args
[i
], "_VTIP_", 6) == 0)
444 tip
= (menu_tip
*)(void *)grub_strtoul(e
->args
[i
] + 6, NULL
, 16);
447 g_ventoy_tip_msg1
= tip
->tip1
;
448 g_ventoy_tip_msg2
= tip
->tip2
;
455 menu_set_chosen_entry (grub_menu_t menu
, int entry
)
457 struct grub_menu_viewer
*cur
;
459 menu_set_chosen_tip(menu
, entry
);
460 for (cur
= viewers
; cur
; cur
= cur
->next
)
461 cur
->set_chosen_entry (entry
, cur
->data
);
465 menu_print_timeout (int timeout
)
467 struct grub_menu_viewer
*cur
;
468 for (cur
= viewers
; cur
; cur
= cur
->next
)
469 cur
->print_timeout (timeout
, cur
->data
);
475 struct grub_menu_viewer
*cur
, *next
;
476 for (cur
= viewers
; cur
; cur
= next
)
479 cur
->fini (cur
->data
);
486 menu_init (int entry
, grub_menu_t menu
, int nested
)
488 struct grub_term_output
*term
;
491 FOR_ACTIVE_TERM_OUTPUTS(term
)
492 if (term
->fullscreen
)
494 if (grub_env_get ("theme"))
496 if (!grub_gfxmenu_try_hook
)
498 grub_dl_load ("gfxmenu");
501 if (grub_gfxmenu_try_hook
)
504 err
= grub_gfxmenu_try_hook (entry
, menu
, nested
);
512 grub_error (GRUB_ERR_BAD_MODULE
,
513 N_("module `%s' isn't loaded"),
516 grub_wait_after_message ();
518 grub_errno
= GRUB_ERR_NONE
;
523 FOR_ACTIVE_TERM_OUTPUTS(term
)
527 if (grub_strcmp (term
->name
, "gfxterm") == 0 && gfxmenu
)
530 err
= grub_menu_try_text (term
, entry
, menu
, nested
);
534 grub_errno
= GRUB_ERR_NONE
;
541 struct grub_menu_viewer
*cur
;
542 for (cur
= viewers
; cur
; cur
= cur
->next
)
543 cur
->clear_timeout (cur
->data
);
547 grub_menu_register_viewer (struct grub_menu_viewer
*viewer
)
549 viewer
->next
= viewers
;
554 menuentry_eq (const char *id
, const char *spec
)
556 const char *ptr1
, *ptr2
;
561 if (*ptr2
== '>' && ptr2
[1] != '>' && *ptr1
== 0)
563 if (*ptr2
== '>' && ptr2
[1] != '>')
577 /* Get the entry number from the variable NAME. */
579 get_entry_number (grub_menu_t menu
, const char *name
)
584 val
= grub_env_get (name
);
590 entry
= (int) grub_strtoul (val
, 0, 0);
592 if (grub_errno
== GRUB_ERR_BAD_NUMBER
)
594 /* See if the variable matches the title of a menu entry. */
595 grub_menu_entry_t e
= menu
->entry_list
;
598 grub_errno
= GRUB_ERR_NONE
;
602 if (menuentry_eq (e
->title
, val
)
603 || menuentry_eq (e
->id
, val
))
615 if (grub_errno
!= GRUB_ERR_NONE
)
617 grub_errno
= GRUB_ERR_NONE
;
626 /* Check whether a second has elapsed since the last tick. If so, adjust
627 the timer and return 1; otherwise, return 0. */
629 has_second_elapsed (grub_uint64_t
*saved_time
)
631 grub_uint64_t current_time
;
633 current_time
= grub_get_time_ms ();
634 if (current_time
- *saved_time
>= 1000)
636 *saved_time
= current_time
;
644 print_countdown (struct grub_term_coordinate
*pos
, int n
)
646 grub_term_restore_pos (pos
);
647 /* NOTE: Do not remove the trailing space characters.
648 They are required to clear the line. */
649 grub_printf ("%d ", n
);
653 #define GRUB_MENU_PAGE_SIZE 10
655 /* Show the menu and handle menu entry selection. Returns the menu entry
656 index that should be executed or -1 if no entry should be executed (e.g.,
657 Esc pressed to exit a sub-menu or switching menu viewers).
658 If the return value is not -1, then *AUTO_BOOT is nonzero iff the menu
659 entry to be executed is a result of an automatic default selection because
662 run_menu (grub_menu_t menu
, int nested
, int *auto_boot
)
665 grub_uint64_t saved_time
;
666 int default_entry
,current_entry
;
668 enum timeout_style timeout_style
;
670 default_entry
= get_entry_number (menu
, "default");
672 if (g_ventoy_suppress_esc
)
673 default_entry
= g_ventoy_suppress_esc_default
;
674 else if (g_ventoy_last_entry
>= 0 && g_ventoy_last_entry
< menu
->size
) {
675 default_entry
= g_ventoy_last_entry
;
677 /* If DEFAULT_ENTRY is not within the menu entries, fall back to
679 else if (default_entry
< 0 || default_entry
>= menu
->size
)
682 timeout
= grub_menu_get_timeout ();
684 /* If there is no timeout, the "countdown" and "hidden" styles result in
685 the system doing nothing and providing no or very little indication
686 why. Technically this is what the user asked for, but it's not very
687 useful and likely to be a source of confusion, so we disallow this. */
688 grub_env_unset ("timeout_style");
690 timeout_style
= get_timeout_style ();
692 if (timeout_style
== TIMEOUT_STYLE_COUNTDOWN
693 || timeout_style
== TIMEOUT_STYLE_HIDDEN
)
695 static struct grub_term_coordinate
*pos
;
698 if (timeout_style
== TIMEOUT_STYLE_COUNTDOWN
&& timeout
)
700 pos
= grub_term_save_pos ();
701 print_countdown (pos
, timeout
);
704 /* Enter interruptible sleep until Escape or a menu hotkey is pressed,
705 or the timeout expires. */
706 saved_time
= grub_get_time_ms ();
711 key
= grub_getkey_noblock ();
712 if (key
!= GRUB_TERM_NO_KEY
)
714 entry
= get_entry_index_by_hotkey (menu
, key
);
718 if (key
== GRUB_TERM_ESC
)
724 if (timeout
> 0 && has_second_elapsed (&saved_time
))
727 if (timeout_style
== TIMEOUT_STYLE_COUNTDOWN
)
728 print_countdown (pos
, timeout
);
732 /* We will fall through to auto-booting the default entry. */
736 grub_env_unset ("timeout");
737 grub_env_unset ("timeout_style");
745 /* If timeout is 0, drawing is pointless (and ugly). */
749 return default_entry
;
752 current_entry
= default_entry
;
755 menu_set_chosen_tip(menu
, current_entry
);
756 menu_init (current_entry
, menu
, nested
);
758 /* Initialize the time. */
759 saved_time
= grub_get_time_ms ();
761 timeout
= grub_menu_get_timeout ();
764 menu_print_timeout (timeout
);
771 timeout
= grub_menu_get_timeout ();
773 if (grub_normal_exit_level
)
776 if (timeout
> 0 && has_second_elapsed (&saved_time
))
779 grub_menu_set_timeout (timeout
);
780 menu_print_timeout (timeout
);
785 grub_env_unset ("timeout");
788 return default_entry
;
791 c
= grub_getkey_noblock ();
793 /* Negative values are returned on error. */
794 if ((c
!= GRUB_TERM_NO_KEY
) && (c
> 0))
798 grub_env_unset ("timeout");
799 grub_env_unset ("fallback");
805 case GRUB_TERM_KEY_HOME
:
806 case GRUB_TERM_CTRL
| 'a':
808 menu_set_chosen_entry (menu
, current_entry
);
811 case GRUB_TERM_KEY_END
:
812 case GRUB_TERM_CTRL
| 'e':
813 current_entry
= menu
->size
- 1;
814 menu_set_chosen_entry (menu
, current_entry
);
817 case GRUB_TERM_KEY_UP
:
818 case GRUB_TERM_CTRL
| 'p':
820 if (current_entry
> 0)
822 menu_set_chosen_entry (menu
, current_entry
);
825 case GRUB_TERM_CTRL
| 'n':
826 case GRUB_TERM_KEY_DOWN
:
828 if (current_entry
< menu
->size
- 1)
830 menu_set_chosen_entry (menu
, current_entry
);
833 case GRUB_TERM_CTRL
| 'g':
834 case GRUB_TERM_KEY_PPAGE
:
835 if (current_entry
< GRUB_MENU_PAGE_SIZE
)
838 current_entry
-= GRUB_MENU_PAGE_SIZE
;
839 menu_set_chosen_entry (menu
, current_entry
);
842 case GRUB_TERM_CTRL
| 'c':
843 case GRUB_TERM_KEY_NPAGE
:
844 if (current_entry
+ GRUB_MENU_PAGE_SIZE
< menu
->size
)
845 current_entry
+= GRUB_MENU_PAGE_SIZE
;
847 current_entry
= menu
->size
- 1;
848 menu_set_chosen_entry (menu
, current_entry
);
853 // case GRUB_TERM_KEY_RIGHT:
854 case GRUB_TERM_CTRL
| 'f':
857 return current_entry
;
860 if (nested
&& 0 == g_ventoy_suppress_esc
)
869 grub_cmdline_run (1, 0);
875 grub_menu_entry_t e
= grub_menu_get_entry (menu
, current_entry
);
877 grub_menu_entry_run (e
);
881 case GRUB_TERM_KEY_F2
:
883 VTOY_COMM_HOTKEY("VTOY_F2_CMD");
885 case GRUB_TERM_KEY_F3
:
887 VTOY_COMM_HOTKEY("VTOY_F3_CMD");
889 case GRUB_TERM_KEY_F4
:
891 VTOY_COMM_HOTKEY("VTOY_F4_CMD");
893 case GRUB_TERM_KEY_F5
:
895 VTOY_COMM_HOTKEY("VTOY_F5_CMD");
897 case GRUB_TERM_KEY_F6
:
899 VTOY_COMM_HOTKEY("VTOY_F6_CMD");
901 case GRUB_TERM_KEY_F7
:
903 if (g_ventoy_terminal_output
== 0)
905 grub_script_execute_sourcecode("terminal_output console");
906 g_ventoy_terminal_output
= 1;
910 grub_script_execute_sourcecode("terminal_output gfxterm");
911 g_ventoy_terminal_output
= 0;
914 case GRUB_TERM_KEY_F1
:
917 g_ventoy_memdisk_mode
= 1 - g_ventoy_memdisk_mode
;
918 g_ventoy_menu_refresh
= 1;
921 case (GRUB_TERM_CTRL
| 'i'):
923 g_ventoy_iso_raw
= 1 - g_ventoy_iso_raw
;
924 g_ventoy_menu_refresh
= 1;
927 case (GRUB_TERM_CTRL
| 'r'):
929 g_ventoy_grub2_mode
= 1 - g_ventoy_grub2_mode
;
930 g_ventoy_menu_refresh
= 1;
933 case (GRUB_TERM_CTRL
| 'w'):
935 g_ventoy_wimboot_mode
= 1 - g_ventoy_wimboot_mode
;
936 g_ventoy_menu_refresh
= 1;
939 case (GRUB_TERM_CTRL
| 'u'):
941 g_ventoy_iso_uefi_drv
= 1 - g_ventoy_iso_uefi_drv
;
942 g_ventoy_menu_refresh
= 1;
945 case (GRUB_TERM_CTRL
| 'h'):
948 cmdstr
= grub_env_get("VTOY_HELP_CMD");
951 grub_script_execute_sourcecode(cmdstr
);
952 while (grub_getkey() != GRUB_TERM_ESC
)
959 case (GRUB_TERM_CTRL
| 'm'):
962 if (g_ventoy_cur_img_path
)
964 grub_env_set("VTOY_CHKSUM_FILE_PATH", g_ventoy_cur_img_path
);
965 cmdstr
= grub_env_get("VTOY_CHKSUM_CMD");
969 grub_script_execute_sourcecode(cmdstr
);
975 grub_env_set("VTOY_CHKSUM_FILE_PATH", "X");
983 entry
= get_entry_index_by_hotkey (menu
, c
);
996 /* Never reach here. */
999 /* Callback invoked immediately before a menu entry is executed. */
1001 notify_booting (grub_menu_entry_t entry
,
1002 void *userdata
__attribute__((unused
)))
1005 grub_printf_ (N_("Booting `%s'"), entry
->title
);
1006 grub_printf ("\n\n");
1009 /* Callback invoked when a default menu entry executed because of a timeout
1010 has failed and an attempt will be made to execute the next fallback
1013 notify_fallback (grub_menu_entry_t entry
,
1014 void *userdata
__attribute__((unused
)))
1016 grub_printf ("\n ");
1017 grub_printf_ (N_("Falling back to `%s'"), entry
->title
);
1018 grub_printf ("\n\n");
1019 grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS
);
1022 /* Callback invoked when a menu entry has failed and there is no remaining
1023 fallback entry to attempt. */
1025 notify_execution_failure (void *userdata
__attribute__((unused
)))
1027 if (grub_errno
!= GRUB_ERR_NONE
)
1029 grub_print_error ();
1030 grub_errno
= GRUB_ERR_NONE
;
1032 grub_printf ("\n ");
1033 grub_printf_ (N_("Failed to boot both default and fallback entries.\n"));
1034 grub_wait_after_message ();
1037 /* Callbacks used by the text menu to provide user feedback when menu entries
1039 static struct grub_menu_execute_callback execution_callback
=
1041 .notify_booting
= notify_booting
,
1042 .notify_fallback
= notify_fallback
,
1043 .notify_failure
= notify_execution_failure
1047 show_menu (grub_menu_t menu
, int nested
, int autobooted
)
1050 def
= grub_env_get("VTOY_DEFAULT_IMAGE");
1055 grub_menu_entry_t e
;
1058 boot_entry
= run_menu (menu
, nested
, &auto_boot
);
1062 if (auto_boot
&& def
&& grub_strcmp(def
, "VTOY_EXIT") == 0) {
1066 if (autobooted
== 0 && auto_boot
== 0) {
1067 g_ventoy_last_entry
= boot_entry
;
1068 if (g_ventoy_menu_esc
)
1072 if (autobooted
== 0 && g_ventoy_menu_esc
&& auto_boot
) {
1073 g_ventoy_last_entry
= boot_entry
;
1077 e
= grub_menu_get_entry (menu
, boot_entry
);
1079 continue; /* Menu is empty. */
1081 if (2 == e
->argc
&& e
->args
&& e
->args
[1] && grub_strncmp(e
->args
[1], "VTOY_RET", 8) == 0)
1087 grub_menu_execute_with_fallback (menu
, e
, autobooted
,
1088 &execution_callback
, 0);
1090 grub_menu_execute_entry (e
, 0);
1094 if (2 == e
->argc
&& e
->args
&& e
->args
[1] && grub_strncmp(e
->args
[1], "VTOY_RUN_RET", 12) == 0)
1098 return GRUB_ERR_NONE
;
1102 grub_show_menu (grub_menu_t menu
, int nested
, int autoboot
)
1104 grub_err_t err1
, err2
;
1108 err1
= show_menu (menu
, nested
, autoboot
);
1110 grub_print_error ();
1112 if (grub_normal_exit_level
)
1115 err2
= grub_auth_check_authentication (NULL
);
1118 grub_print_error ();
1119 grub_errno
= GRUB_ERR_NONE
;