Allow hotkeys to interrupt hidden menu
RFC PATCH 1/1 Allow hotkeys to interrupt hidden menu
One of my colleagues, Franz Hsieh (CCed) sent this patch to
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1178618. It has a few minor implementation issues, and I'll follow up with my own review in a few minutes (it certainly also requires rebasing to apply properly to trunk), but I wanted to ask what people thought of the design, particularly since it adds new configuration options. The basic idea is to allow a hidden menu (sleep --interruptible) to be interrupted by a hotkey which is then passed on to the menu code, so that you can use menuentry --hotkey and still hotkey-select an item from the hidden menu.
I suggested adding an "unput"-type feature to the terminal layer to support this, but the approach used here of stuffing the hotkey into an environment variable should work just as well and avoids the need to add more code to the kernel.
grub-core/commands/sleep.c +64 -7
@@ -24,6 +24,7 @@#include <grub/misc.h> #include <grub/extcmd.h> #include <grub/i18n.h> +#include <grub/env.h> GRUB_MOD_LICENSE ("GPLv3+" );
@@ -31,9 +32,31 @@ { {"verbose", 'v', 0, N_("Verbose countdown."), 0, 0}, {"interruptible", 'i', 0, N_("Interruptible with ESC."), 0, 0}, + {"function-key", 'f', 0, + N_("Interruptible with function key."), "KEY", ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} }; +static struct +{ + char *name; + int key; +} function_key_aliases[] = + { + {"f1", GRUB_TERM_KEY_F1}, + {"f2", GRUB_TERM_KEY_F2}, + {"f3", GRUB_TERM_KEY_F3}, + {"f4", GRUB_TERM_KEY_F4}, + {"f5", GRUB_TERM_KEY_F5}, + {"f6", GRUB_TERM_KEY_F6}, + {"f7", GRUB_TERM_KEY_F7}, + {"f8", GRUB_TERM_KEY_F8}, + {"f9", GRUB_TERM_KEY_F9}, + {"f10", GRUB_TERM_KEY_F10}, + {"f11", GRUB_TERM_KEY_F11}, + {"f12", GRUB_TERM_KEY_F12}, + }; + static grub_uint16_t *pos; static void
@@ -46,7 +69,21 @@ }static int -grub_check_keyboard (void ) +grub_parse_function_key (const char * name) +{ +unsigned i; +if (!name) +return 0 ; + +for (i =0 ; i <ARRAY_SIZE (function_key_aliases); i++) +if (grub_strcmp (name, function_key_aliases[i].name) ==0 ) +return function_key_aliases[i].key; + +return 0 ; +} + +static int +grub_check_keyboard (int fnkey) {int mods =0 ;grub_term_input_t term;
@@ -64,22 +101,34 @@ (mods & (GRUB_TERM_STATUS_LSHIFT | GRUB_TERM_STATUS_RSHIFT)) != 0)return 1 ; -if (grub_checkkey () >=0 &&grub_getkey () ==GRUB_TERM_ESC ) -return 1 ; +if (grub_checkkey () >=0 ) + { +int key =grub_getkey (); +if (key ==GRUB_TERM_ESC ) +return 1 ; + +if (key == fnkey) + { +char hotkey[32 ] = {0 }; +grub_snprintf (hotkey,32 ,"%d" , key); +grub_env_set ("hotkey" , (char *)&hotkey); +return 1 ; + } + }return 0 ; }/* Based on grub_millisleep() from kern/generic/millisleep.c. */ static int -grub_interruptible_millisleep (grub_uint32_t ms) +grub_interruptible_millisleep (grub_uint32_t ms,int key) {grub_uint64_t start; start =grub_get_time_ms ();while (grub_get_time_ms () - start < ms) -if (grub_check_keyboard ()) +if (grub_check_keyboard (key))return 1 ;return 0 ;
@@ -90,6 +139,7 @@ {struct grub_arg_list *state = ctxt->state;int n; +int key =0 ;if (argc !=1 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"missing operand" );
@@ -104,14 +154,21 @@ pos =grub_term_save_pos (); +if (state[2 ].set) + { + key =grub_parse_function_key (state[2 ].arg); +if (key ==0 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid function key" ); + } +for (; n; n--) {if (state[0 ].set)do_print (n); -if (state[1 ].set) +if (state[1 ].set || state[2 ].set) { -if (grub_interruptible_millisleep (1000 )) +if (grub_interruptible_millisleep (1000 , key))return 1 ; }else
grub-core/normal/menu.c +57 -10
99 lines not on this page · raw message
util/grub-mkconfig.in +2 -1
@@ -251,7 +251,8 @@ GRUB_INIT_TUNE \ GRUB_SAVEDEFAULT \ GRUB_BADRAM \ - GRUB_RECORDFAIL_TIMEOUT + GRUB_RECORDFAIL_TIMEOUT \ + GRUB_HIDDEN_TIMEOUT_HOTKEY if test "x${grub_cfg}" != "x"; then rm -f ${grub_cfg}.new
util/grub.d/30_os-prober.in +8 -2
@@ -34,6 +34,12 @@ verbose=" --verbose" fi + if [ "x${GRUB_HIDDEN_TIMEOUT_HOTKEY}" = "x" ] ; then + hotkey= + else + hotkey=" --function-key ${GRUB_HIDDEN_TIMEOUT_HOTKEY}" + fi + if [ "x${1}" = "x0" ] ; then cat <<EOF if [ "x\${timeout}" != "x-1" ]; then
@@ -44,7 +50,7 @@ set timeout=0 fi else - if sleep$verbose --interruptible 3 ; then + if sleep$verbose --interruptible 3$hotkey ; then set timeout=0 fi fi
@@ -53,7 +59,7 @@ else cat << EOF if [ "x\${timeout}" != "x-1" ]; then - if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then + if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT}$hotkey ; then set timeout=0 fi fi
Thanks,
Signature · 1 line
Colin Watson [[email protected]]
Hi Franz,
Throughout this patch, please take care to adhere to the GRUB coding style. This is definitely an improvement over previous versions I've reviewed, but it still has a number of places where functions are called or declared with no space before the opening parenthesis. That is, "function()" should become "function ()". I know it's a minor point, but it makes code much easier to read when it's all in the same style.
Quoted 10 lines · Franz Hsieh (via Colin Watson)
grub-core/commands/sleep.c +10
-0+static struct +{ +char *name; +int key; +} function_key_aliases[] = + { + {"f1" ,GRUB_TERM_KEY_F1 }, + {"f2" ,GRUB_TERM_KEY_F2 }, + {"f3" ,GRUB_TERM_KEY_F3 }, + {"f4" ,GRUB_TERM_KEY_F4 },
grub-core/commands/sleep.c line 59
Quoted 10 lines
grub-core/commands/sleep.c +10
-0+ {"f5", GRUB_TERM_KEY_F5}, + {"f6", GRUB_TERM_KEY_F6}, + {"f7", GRUB_TERM_KEY_F7}, + {"f8", GRUB_TERM_KEY_F8}, + {"f9", GRUB_TERM_KEY_F9}, + {"f10", GRUB_TERM_KEY_F10}, + {"f11", GRUB_TERM_KEY_F11}, + {"f12", GRUB_TERM_KEY_F12}, + }; +
This is essentially a copy of hotkey_aliases from grub-core/commands/menuentry.c, and there's duplicated lookup code as well. Can you find any way to share it? Since we certainly don't want to put this in the kernel, and neither the sleep module nor the normal module really ought to depend on the other, I suspect that doing so would require a new module for shared menu code, which may well be overkill for this, but it's worth a look.
At the very least it would be a good idea to bring the contents of this structure into sync with hotkey_aliases and add comments to encourage developers to keep them that way.
I think we should also call this kind of thing simply "hotkey" consistently across the code, rather than it sometimes being "function_key" or "fnkey".
grub-core/commands/sleep.c line 116
Quoted 7 lines
grub-core/commands/sleep.c +7
-0+if (key == fnkey) + { +char hotkey[32 ] = {0 }; +grub_snprintf (hotkey,32 ,"%d" , key); +grub_env_set ("hotkey" , (char *)&hotkey); +return 1 ; + }
We've generally tried to get rid of this kind of static allocation. Use grub_xasprintf instead:
if (key == fnkey)
{
char *hotkey = grub_xasprintf ("%d", key);
grub_env_set ("hotkey", hotkey);
grub_free (hotkey);
return 1;
}grub-core/normal/menu.c line 107
Quoted 2 lines
grub-core/normal/menu.c +2
-0+int +grub_menu_get_hotkey (void )
This function is only used in this file, so it should be static.
Quoted 41 lines
Index: grub2-1.99/util/grub-mkconfig.in
===================================================================util/grub-mkconfig.in +2
-1@@ -251,7 +251,8 @@ GRUB_INIT_TUNE \ GRUB_SAVEDEFAULT \ GRUB_BADRAM \ - GRUB_RECORDFAIL_TIMEOUT + GRUB_RECORDFAIL_TIMEOUT \ + GRUB_HIDDEN_TIMEOUT_HOTKEY if test "x${grub_cfg}" != "x"; then rm -f ${grub_cfg}.newIndex: grub2-1.99/util/grub.d/30_os-prober.in
===================================================================util/grub.d/30_os-prober.in +7
-1@@ -34,6 +34,12 @@ verbose=" --verbose" fi + if [ "x${GRUB_HIDDEN_TIMEOUT_HOTKEY}" = "x" ] ; then + hotkey= + else + hotkey=" --function-key ${GRUB_HIDDEN_TIMEOUT_HOTKEY}" + fi + if [ "x${1}" = "x0" ] ; then cat <<EOF if [ "x\${timeout}" != "x-1" ]; then@@ -44,7 +50,7 @@ set timeout=0 fi else - if sleep$verbose --interruptible 3 ; then + if sleep$verbose --interruptible 3$hotkey ; then set timeout=0 fi fi
util/grub.d/30_os-prober.in line 65
Quoted 8 lines
util/grub.d/30_os-prober.in +1
-1@@ -53,7 +59,7 @@ else cat << EOF if [ "x\${timeout}" != "x-1" ]; then - if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then + if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT}$hotkey ; then set timeout=0 fi fi
Rather than having to configure this explicitly, I have an alternative suggestion, which ties into my earlier suggestion of making the hotkey code a bit more shared. Why not have sleep --interruptible look up the hotkeys configured in the menu and automatically honour any of those? That way you wouldn't have to configure hotkeys in two places (grub.cfg and /etc/default/grub). Plus, I'm always more comfortable with patches that don't require adding configuration options.
Thanks,
Signature · 1 line
Colin Watson [[email protected]]
В Wed, 11 Sep 2013 14:31:29 +0100
Colin Watson <[email protected]> пишет:
Quoted 5 lines
Rather than having to configure this explicitly, I have an alternative suggestion, which ties into my earlier suggestion of making the hotkey code a bit more shared. Why not have sleep --interruptible look up the hotkeys configured in the menu and automatically honour any of those?
+1
Quoted 6 lines
That way you wouldn't have to configure hotkeys in two places (grub.cfg and
/etc/default/grub). Plus, I'm always more comfortable with patches that don't require adding configuration options.Thanks,
Quoted 32 lines · Colin Watson
Hi Franz,
Throughout this patch, please take care to adhere to the GRUB coding style. This is definitely an improvement over previous versions I've reviewed, but it still has a number of places where functions are called or declared with no space before the opening parenthesis. That is, "
function()" should become "function ()". I know it's a minor point, but it makes code much easier to read when it's all in the same style.Quoted 10 lines · Franz Hsieh (via Colin Watson)
grub-core/commands/sleep.c +10
-0+static struct +{ +char *name; +int key; +} function_key_aliases[] = + { + {"f1" ,GRUB_TERM_KEY_F1 }, + {"f2" ,GRUB_TERM_KEY_F2 }, + {"f3" ,GRUB_TERM_KEY_F3 }, + {"f4" ,GRUB_TERM_KEY_F4 },grub-core/commands/sleep.c line 59
Quoted 10 lines
grub-core/commands/sleep.c +10
-0+ {"f5", GRUB_TERM_KEY_F5}, + {"f6", GRUB_TERM_KEY_F6}, + {"f7", GRUB_TERM_KEY_F7}, + {"f8", GRUB_TERM_KEY_F8}, + {"f9", GRUB_TERM_KEY_F9}, + {"f10", GRUB_TERM_KEY_F10}, + {"f11", GRUB_TERM_KEY_F11}, + {"f12", GRUB_TERM_KEY_F12}, + }; +
Quoted 8 lines
This is essentially a copy of
hotkey_aliasesfromgrub-core/commands/menuentry.c, and there's duplicated lookup code as well. Can you find any way to share it? Since we certainly don't want to put this in the kernel, and neither the sleep module nor the normal module really ought to depend on the other, I suspect that doing so would require a new module for shared menu code, which may well be overkill for this, but it's worth a look.
I also agree to remove duplicate code, but seems not easy to do it unless we have a shared module, right? Well it would take me some time to evaluate.
At the very least it would be a good idea to bring the contents of this
Quoted 29 lines
structure into sync with
hotkey_aliasesand add comments to encourage developers to keep them that way.I think we should also call this kind of thing simply "hotkey" consistently across the code, rather than it sometimes being "
function_key" or "fnkey".grub-core/commands/sleep.c line 116
Quoted 7 lines
grub-core/commands/sleep.c +7
-0+if (key == fnkey) + { +char hotkey[32 ] = {0 }; +grub_snprintf (hotkey,32 ,"%d" , key); +grub_env_set ("hotkey" , (char *)&hotkey); +return 1 ; + }We've generally tried to get rid of this kind of static allocation. Use
grub_xasprintfinstead:if (key == fnkey) { char *hotkey = grub_xasprintf ("%d", key); grub_env_set ("hotkey", hotkey); grub_free (hotkey); return 1; }
Quoted 5 lines
grub-core/normal/menu.c line 107
Quoted 2 lines
grub-core/normal/menu.c +2
-0+int +grub_menu_get_hotkey (void )This function is only used in this file, so it should be static.
These idea are good and I will do these changes in my patch.
Rather than having to configure this explicitly, I have an alternative
Quoted 7 lines
suggestion, which ties into my earlier suggestion of making the hotkey code a bit more shared. Why not have sleep --interruptible look up the hotkeys configured in the menu and automatically honour any of those? That way you wouldn't have to configure hotkeys in two places (grub.cfg and
/etc/default/grub). Plus, I'm always more comfortable with patches that don't require adding configuration options.
Agree with Colin's points and I will update the patch.
By the way I would like to combine --function-key and --interruptible. I think
it is a simple way that sleep.mod always checks ESC for interrupt and f1~f12 for the
hotkey.
Thanks for your reviews and if there is any good suggestion, please feel free to tell me.
Regards,
Franz Hsieh
Quoted 47 lines · Franz Hsieh
On Wed, Sep 11, 2013 at 9:31 PM, Colin Watson <[email protected] <mailto:[email protected]>> wrote:
Hi Franz, Throughout this patch, please take care to adhere to the GRUB coding style. This is definitely an improvement over previous versions I've reviewed, but it still has a number of places where functions are called or declared with no space before the opening parenthesis. That is, "function()" should become "function ()". I know it's a minor point, but it makes code much easier to read when it's all in the same style. On Wed, Sep 11, 2013 at 02:18:04PM +0100, Franz Hsieh (via Colin Watson) wrote: > +static struct > +{ > + char *name; > + int key; > +} function_key_aliases[] = > + { > + {"f1", GRUB_TERM_KEY_F1}, > + {"f2", GRUB_TERM_KEY_F2}, > + {"f3", GRUB_TERM_KEY_F3}, > + {"f4", GRUB_TERM_KEY_F4}, > + {"f5", GRUB_TERM_KEY_F5}, > + {"f6", GRUB_TERM_KEY_F6}, > + {"f7", GRUB_TERM_KEY_F7}, > + {"f8", GRUB_TERM_KEY_F8}, > + {"f9", GRUB_TERM_KEY_F9}, > + {"f10", GRUB_TERM_KEY_F10}, > + {"f11", GRUB_TERM_KEY_F11}, > + {"f12", GRUB_TERM_KEY_F12}, > + }; > + This is essentially a copy of hotkey_aliases from grub-core/commands/menuentry.c, and there's duplicated lookup code as well. Can you find any way to share it? Since we certainly don't want to put this in the kernel, and neither the sleep module nor the normal module really ought to depend on the other, I suspect that doing so would require a new module for shared menu code, which may well be overkill for this, but it's worth a look.
Quoted 2 lines
I also agree to remove duplicate code, but seems not easy to do it unless we have a shared module, right? Well it would take me some time to evaluate.
Why not just allow any key interrupt sleep and if it's not escape using ungetc-like code (with real ungetc code or global variable of some kind)?
Hi, there
I had merged the patch for enabling hotkey in grub silent mode to
grub-trunk.
The --function-key now has been removed from sleep.mod, now sleep.mod will monitor all function keys, delete, tab and backspace.
Thanks!
Franz Hsieh
Quoted 104 lines · Franz Hsieh
Quoted 32 lines · Colin Watson
Hi Franz,
Throughout this patch, please take care to adhere to the GRUB coding style. This is definitely an improvement over previous versions I've reviewed, but it still has a number of places where functions are called or declared with no space before the opening parenthesis. That is, "
function()" should become "function ()". I know it's a minor point, but it makes code much easier to read when it's all in the same style.Quoted 10 lines · Franz Hsieh (via Colin Watson)
(quoted diff) +10
-0+static struct +{ + char *name; + int key; +} function_key_aliases[] = + { + {"f1", GRUB_TERM_KEY_F1}, + {"f2", GRUB_TERM_KEY_F2}, + {"f3", GRUB_TERM_KEY_F3}, + {"f4", GRUB_TERM_KEY_F4},Review
Quoted 10 lines
(quoted diff) +10
-0+ {"f5", GRUB_TERM_KEY_F5}, + {"f6", GRUB_TERM_KEY_F6}, + {"f7", GRUB_TERM_KEY_F7}, + {"f8", GRUB_TERM_KEY_F8}, + {"f9", GRUB_TERM_KEY_F9}, + {"f10", GRUB_TERM_KEY_F10}, + {"f11", GRUB_TERM_KEY_F11}, + {"f12", GRUB_TERM_KEY_F12}, + }; +Quoted 8 lines
This is essentially a copy of
hotkey_aliasesfromgrub-core/commands/menuentry.c, and there's duplicated lookup code as well. Can you find any way to share it? Since we certainly don't want to put this in the kernel, and neither the sleep module nor the normal module really ought to depend on the other, I suspect that doing so would require a new module for shared menu code, which may well be overkill for this, but it's worth a look.I also agree to remove duplicate code, but seems not easy to do it unless we have a shared module, right? Well it would take me some time to evaluate.
At the very least it would be a good idea to bring the contents of this
Quoted 29 lines
structure into sync with
hotkey_aliasesand add comments to encourage developers to keep them that way.I think we should also call this kind of thing simply "hotkey" consistently across the code, rather than it sometimes being "
function_key" or "fnkey".Review
Quoted 7 lines
(quoted diff) +7
-0+ if (key == fnkey) + { + char hotkey[32] = {0}; + grub_snprintf(hotkey, 32, "%d", key); + grub_env_set("hotkey", (char*)&hotkey); + return 1; + }We've generally tried to get rid of this kind of static allocation. Use
grub_xasprintfinstead:if (key == fnkey) { char *hotkey = grub_xasprintf ("%d", key); grub_env_set ("hotkey", hotkey); grub_free (hotkey); return 1; }Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+int +grub_menu_get_hotkey (void)This function is only used in this file, so it should be static.
These idea are good and I will do these changes in my patch.
Rather than having to configure this explicitly, I have an alternative
Quoted 7 lines
suggestion, which ties into my earlier suggestion of making the hotkey code a bit more shared. Why not have sleep --interruptible look up the hotkeys configured in the menu and automatically honour any of those? That way you wouldn't have to configure hotkeys in two places (grub.cfg and
/etc/default/grub). Plus, I'm always more comfortable with patches that don't require adding configuration options.Agree with Colin's points and I will update the patch.
By the way I would like to combine --function-key and --interruptible. I think
it is a simple way that sleep.mod always checks ESC for interrupt and f1~f12 for the
hotkey.
Quoted 7 lines
Thanks for your reviews and if there is any good suggestion, please feel free to tell me.
Regards,
Franz Hsieh
=== modified file 'grub-core/commands/sleep.c'
grub-core/commands/sleep.c +41 -2
@@ -24,6 +24,7 @@#include <grub/misc.h> #include <grub/extcmd.h> #include <grub/i18n.h> +#include <grub/env.h> GRUB_MOD_LICENSE ("GPLv3+" );
@@ -46,18 +47,56 @@grub_refresh (); } +static int +grub_check_hotkey (int hotkey) +{ +switch (hotkey) + { +case GRUB_TERM_KEY_F1 : +case GRUB_TERM_KEY_F2 : +case GRUB_TERM_KEY_F3 : +case GRUB_TERM_KEY_F4 : +case GRUB_TERM_KEY_F5 : +case GRUB_TERM_KEY_F6 : +case GRUB_TERM_KEY_F7 : +case GRUB_TERM_KEY_F8 : +case GRUB_TERM_KEY_F9 : +case GRUB_TERM_KEY_F10 : +case GRUB_TERM_KEY_F11 : +case GRUB_TERM_KEY_F12 : +case GRUB_TERM_KEY_DC : +case GRUB_TERM_BACKSPACE : +case GRUB_TERM_TAB : +return 1 ; + } + +return 0 ; +} +/* Based on grub_millisleep() from kern/generic/millisleep.c. */ static int grub_interruptible_millisleep (grub_uint32_t ms) {grub_uint64_t start; +int key =0 ; start =grub_get_time_ms ();while (grub_get_time_ms () - start < ms) -if (grub_getkey_noblock () ==GRUB_TERM_ESC ) -return 1 ; + { + key =grub_getkey_noblock (); +if (key ==GRUB_TERM_ESC ) +return 1 ; +if (grub_check_hotkey (key)) + { +char *hotkey =grub_xasprintf ("%d" , key); +grub_env_set ("hotkey" , hotkey); +grub_free (hotkey); +return 1 ; + } + } +return 0 ; }
=== modified file 'grub-core/normal/menu.c'
grub-core/normal/menu.c +62 -13
107 lines not on this page · raw message
=== modified file 'include/grub/menu.h'
include/grub/menu.h +1 -0
@@ -96,6 +96,7 @@grub_menu_entry_t grub_menu_get_entry (grub_menu_t menu,int no);int grub_menu_get_timeout (void ); +int grub_menu_get_hotkey (void );void grub_menu_set_timeout (int timeout);void grub_menu_entry_run (grub_menu_entry_t entry);int grub_menu_get_default_entry_index (grub_menu_t menu);
Quoted 7 lines · Franz Hsieh
Hi, there
I had merged the patch for enabling hotkey in grub silent mode to
grub-trunk.
The --function-key now has been removed from sleep.mod, now sleep.mod will monitor all function keys, delete, tab and backspace.
Have you missed on-going opposition, discussion and improvement proposals from me?
I was going to revert the patch but found out that you didn't actually commit it, please see my comments to make it acceptable and don't push it.
Quoted 11 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 7 lines
* Hi, there*
* *
* I had merged the patch for enabling hotkey in grub silent mode to*
* grub-trunk.*
* The --function-key now has been removed from sleep.mod, now sleep.mod will*
* monitor all function keys, delete, tab and backspace.*
* *Have you missed on-going opposition, discussion and improvement proposals from me?
I was going to revert the patch but found out that you didn't actually commit it, please see my comments to make it acceptable and don't push it.
Sorry I did not say it clearly, I downloaded sources from grub-trunk, add my changes,
and finished the patch file. I haven't committed the patch to trunk yet.
I looked at the codes, there is no ungetkey function to do like ungetc. So currently
I made it to read all keys but only accept function keys / delete / backspace and Esc
keys to interrupt the sleep thread.
Only function keys / delete key / backspace key are allowed for hotkey and will be saved to the hotkey environment variable.
Quoted 127 lines · Franz Hsieh
Hi, there
I had merged the patch for enabling hotkey in grub silent mode to
grub-trunk.
The --function-key now has been removed from sleep.mod, now sleep.mod
will
monitor all function keys, delete, tab and backspace.Thanks!
Franz Hsieh
Quoted 111 lines · Franz Hsieh
Quoted 32 lines · Colin Watson
Hi Franz,
Throughout this patch, please take care to adhere to the GRUB coding style. This is definitely an improvement over previous versions I've reviewed, but it still has a number of places where functions are called or declared with no space before the opening parenthesis. That is, "
function()" should become "function ()". I know it's a minor point, but it makes code much easier to read when it's all in the same style.Quoted 10 lines · Franz Hsieh (via Colin Watson)
(quoted diff) +10
-0+static struct +{ + char *name; + int key; +} function_key_aliases[] = + { + {"f1", GRUB_TERM_KEY_F1}, + {"f2", GRUB_TERM_KEY_F2}, + {"f3", GRUB_TERM_KEY_F3}, + {"f4", GRUB_TERM_KEY_F4},Review
Quoted 10 lines
(quoted diff) +10
-0+ {"f5", GRUB_TERM_KEY_F5}, + {"f6", GRUB_TERM_KEY_F6}, + {"f7", GRUB_TERM_KEY_F7}, + {"f8", GRUB_TERM_KEY_F8}, + {"f9", GRUB_TERM_KEY_F9}, + {"f10", GRUB_TERM_KEY_F10}, + {"f11", GRUB_TERM_KEY_F11}, + {"f12", GRUB_TERM_KEY_F12}, + }; +Quoted 8 lines
This is essentially a copy of
hotkey_aliasesfromgrub-core/commands/menuentry.c, and there's duplicated lookup code as well. Can you find any way to share it? Since we certainly don't want to put this in the kernel, and neither the sleep module nor the normal module really ought to depend on the other, I suspect that doing so would require a new module for shared menu code, which may well be overkill for this, but it's worth a look.I also agree to remove duplicate code, but seems not easy to do it unless we have a shared module, right? Well it would take me some time to evaluate.
At the very least it would be a good idea to bring the contents of this
Quoted 29 lines
structure into sync with
hotkey_aliasesand add comments to encourage developers to keep them that way.I think we should also call this kind of thing simply "hotkey" consistently across the code, rather than it sometimes being "
function_key" or "fnkey".Review
Quoted 7 lines
(quoted diff) +7
-0+ if (key == fnkey) + { + char hotkey[32] = {0}; + grub_snprintf(hotkey, 32, "%d", key); + grub_env_set("hotkey", (char*)&hotkey); + return 1; + }We've generally tried to get rid of this kind of static allocation. Use
grub_xasprintfinstead:if (key == fnkey) { char *hotkey = grub_xasprintf ("%d", key); grub_env_set ("hotkey", hotkey); grub_free (hotkey); return 1; }Quoted 5 lines
grub-core/normal/menu.c line 104
Quoted 2 lines
grub-core/normal/menu.c +2
-0+int +grub_menu_get_hotkey (void )This function is only used in this file, so it should be static.
These idea are good and I will do these changes in my patch.
Rather than having to configure this explicitly, I have an alternative
Quoted 7 lines
suggestion, which ties into my earlier suggestion of making the hotkey code a bit more shared. Why not have sleep --interruptible look up the hotkeys configured in the menu and automatically honour any of those? That way you wouldn't have to configure hotkeys in two places (grub.cfg and
/etc/default/grub). Plus, I'm always more comfortable with patches that don't require adding configuration options.Agree with Colin's points and I will update the patch.
By the way I would like to combine --function-key and --interruptible. I think
it is a simple way that sleep.mod always checks ESC for interrupt and f1~f12 for the
hotkey.Thanks for your reviews and if there is any good suggestion, please feel free to tell me.
Regards,
Franz Hsieh
Hi Vladimir,
I don't know if l lose any update from you. Would you give me comments
about
the latest hotkey patch?
Summary of the patch:
* allow function keys / delete / backspace to interrupt sleep and set
'hotkey' variable.
* remove key aliases structure.
* using grub_xasprintf instead of grub_snprintf
* unset the 'hotkey' variable quickly when it is unneeded ingrub_menu_get_hotkey
Many thanks!
Franz Hsieh
Quoted 22 lines · Franz Hsieh
Quoted 8 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 7 lines
* Hi, there*
* *
* I had merged the patch for enabling hotkey in grub silent mode to*
* grub-trunk.*
* The --function-key now has been removed from sleep.mod, now sleep.mod will*
* monitor all function keys, delete, tab and backspace.*
* *Quoted 4 lines
Have you missed on-going opposition, discussion and improvement proposals from me?
I was going to revert the patch but found out that you didn't actually commit it, please see my comments to make it acceptable and don't push it.Sorry I did not say it clearly, I downloaded sources from grub-trunk, add my changes, and finished the patch file. I haven't committed the patch to trunk yet.
I looked at the codes, there is no ungetkey function to do like ungetc. So currently I made it to read all keys but only accept function keys / delete / backspace and Esc keys to interrupt the sleep thread.
Quoted 137 lines
Only function keys / delete key / backspace key are allowed for hotkey
and will be saved to the hotkey environment variable.
Quoted 127 lines · Franz Hsieh
Hi, there
I had merged the patch for enabling hotkey in grub silent mode to
grub-trunk.
The --function-key now has been removed from sleep.mod, now sleep.mod
will
monitor all function keys, delete, tab and backspace.Thanks!
Franz Hsieh
Quoted 111 lines · Franz Hsieh
Quoted 32 lines · Colin Watson
Hi Franz,
Throughout this patch, please take care to adhere to the GRUB coding style. This is definitely an improvement over previous versions I've reviewed, but it still has a number of places where functions are called or declared with no space before the opening parenthesis. That is, "
function()" should become "function ()". I know it's a minor point, but it makes code much easier to read when it's all in the same style.Quoted 10 lines · Franz Hsieh (via Colin Watson)
(quoted diff) +10
-0+static struct +{ + char *name; + int key; +} function_key_aliases[] = + { + {"f1", GRUB_TERM_KEY_F1}, + {"f2", GRUB_TERM_KEY_F2}, + {"f3", GRUB_TERM_KEY_F3}, + {"f4", GRUB_TERM_KEY_F4},Review
Quoted 10 lines
(quoted diff) +10
-0+ {"f5", GRUB_TERM_KEY_F5}, + {"f6", GRUB_TERM_KEY_F6}, + {"f7", GRUB_TERM_KEY_F7}, + {"f8", GRUB_TERM_KEY_F8}, + {"f9", GRUB_TERM_KEY_F9}, + {"f10", GRUB_TERM_KEY_F10}, + {"f11", GRUB_TERM_KEY_F11}, + {"f12", GRUB_TERM_KEY_F12}, + }; +Quoted 8 lines
This is essentially a copy of
hotkey_aliasesfromgrub-core/commands/menuentry.c, and there's duplicated lookup code as well. Can you find any way to share it? Since we certainly don't want to put this in the kernel, and neither the sleep module nor the normal module really ought to depend on the other, I suspect that doing so would require a new module for shared menu code, which may well be overkill for this, but it's worth a look.I also agree to remove duplicate code, but seems not easy to do it unless we have a shared module, right? Well it would take me some time to evaluate.
At the very least it would be a good idea to bring the contents of this
Quoted 29 lines
structure into sync with
hotkey_aliasesand add comments to encourage developers to keep them that way.I think we should also call this kind of thing simply "hotkey" consistently across the code, rather than it sometimes being "
function_key" or "fnkey".Review
Quoted 7 lines
(quoted diff) +7
-0+ if (key == fnkey) + { + char hotkey[32] = {0}; + grub_snprintf(hotkey, 32, "%d", key); + grub_env_set("hotkey", (char*)&hotkey); + return 1; + }We've generally tried to get rid of this kind of static allocation. Use
grub_xasprintfinstead:if (key == fnkey) { char *hotkey = grub_xasprintf ("%d", key); grub_env_set ("hotkey", hotkey); grub_free (hotkey); return 1; }Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+int +grub_menu_get_hotkey (void)This function is only used in this file, so it should be static.
These idea are good and I will do these changes in my patch.
Rather than having to configure this explicitly, I have an alternative
Quoted 7 lines
suggestion, which ties into my earlier suggestion of making the hotkey code a bit more shared. Why not have sleep --interruptible look up the hotkeys configured in the menu and automatically honour any of those? That way you wouldn't have to configure hotkeys in two places (grub.cfg and
/etc/default/grub). Plus, I'm always more comfortable with patches that don't require adding configuration options.Agree with Colin's points and I will update the patch.
By the way I would like to combine --function-key and --interruptible. I think
it is a simple way that sleep.mod always checks ESC for interrupt and f1~f12 for the
hotkey.Thanks for your reviews and if there is any good suggestion, please feel free to tell me.
Regards,
Franz Hsieh
=== modified file 'grub-core/commands/sleep.c'
grub-core/commands/sleep.c +41 -2
@@ -24,6 +24,7 @@#include <grub/misc.h> #include <grub/extcmd.h> #include <grub/i18n.h> +#include <grub/env.h> GRUB_MOD_LICENSE ("GPLv3+" );
@@ -46,18 +47,56 @@grub_refresh (); } +static int +grub_check_hotkey (int hotkey) +{ +switch (hotkey) + { +case GRUB_TERM_KEY_F1 : +case GRUB_TERM_KEY_F2 : +case GRUB_TERM_KEY_F3 : +case GRUB_TERM_KEY_F4 : +case GRUB_TERM_KEY_F5 : +case GRUB_TERM_KEY_F6 : +case GRUB_TERM_KEY_F7 : +case GRUB_TERM_KEY_F8 : +case GRUB_TERM_KEY_F9 : +case GRUB_TERM_KEY_F10 : +case GRUB_TERM_KEY_F11 : +case GRUB_TERM_KEY_F12 : +case GRUB_TERM_KEY_DC : +case GRUB_TERM_BACKSPACE : +case GRUB_TERM_TAB : +return 1 ; + } + +return 0 ; +} +/* Based on grub_millisleep() from kern/generic/millisleep.c. */ static int grub_interruptible_millisleep (grub_uint32_t ms) {grub_uint64_t start; +int key =0 ; start =grub_get_time_ms ();while (grub_get_time_ms () - start < ms) -if (grub_getkey_noblock () ==GRUB_TERM_ESC ) -return 1 ; + { + key =grub_getkey_noblock (); +if (key ==GRUB_TERM_ESC ) +return 1 ; +if (grub_check_hotkey (key)) + { +char *hotkey =grub_xasprintf ("%d" , key); +grub_env_set ("hotkey" , hotkey); +grub_free (hotkey); +return 1 ; + } + } +return 0 ; }
=== modified file 'grub-core/normal/menu.c'
grub-core/normal/menu.c +62 -13
107 lines not on this page · raw message
=== modified file 'include/grub/menu.h'
include/grub/menu.h +1 -0
@@ -96,6 +96,7 @@grub_menu_entry_t grub_menu_get_entry (grub_menu_t menu,int no);int grub_menu_get_timeout (void ); +int grub_menu_get_hotkey (void );void grub_menu_set_timeout (int timeout);void grub_menu_entry_run (grub_menu_entry_t entry);int grub_menu_get_default_entry_index (grub_menu_t menu);
Ping. Any updates?
Quoted 196 lines · Franz Hsieh
Hi Vladimir,
I don't know if l lose any update from you. Would you give me comments
about
the latest hotkey patch?Summary of the patch:
* allow function keys / delete / backspace to interrupt sleep and set
'hotkey' variable.
* remove key aliases structure.
* usinggrub_xasprintfinstead ofgrub_snprintf
* unset the 'hotkey' variable quickly when it is unneeded ingrub_menu_get_hotkeyMany thanks!
Franz Hsieh
Quoted 31 lines · Franz Hsieh
Quoted 8 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 8 lines
Hi, there
I had merged the patch for enabling hotkey in grub silent mode to
grub-trunk.
The --function-key now has been removed from sleep.mod, now sleep.mod
will
monitor all function keys, delete, tab and backspace.Quoted 5 lines
Have you missed on-going opposition, discussion and improvement proposals from me?
I was going to revert the patch but found out that you didn't actually commit it, please see my comments to make it acceptable and don't push it.Sorry I did not say it clearly, I downloaded sources from grub-trunk, add my changes,
and finished the patch file. I haven't committed the patch to trunk yet.I looked at the codes, there is no ungetkey function to do like ungetc. So currently
I made it to read all keys but only accept function keys / delete / backspace and Esc
keys to interrupt the sleep thread.Only function keys / delete key / backspace key are allowed for hotkey
Quoted 140 lines
and will be saved to the hotkey environment variable.
Quoted 133 lines · Franz Hsieh
Hi, there
I had merged the patch for enabling hotkey in grub silent mode to
grub-trunk.
The --function-key now has been removed from sleep.mod, now sleep.mod
will
monitor all function keys, delete, tab and backspace.Thanks!
Franz Hsieh
Quoted 116 lines · Franz Hsieh
Quoted 35 lines · Colin Watson
Hi Franz,
Throughout this patch, please take care to adhere to the GRUB coding style. This is definitely an improvement over previous versions I've reviewed, but it still has a number of places where functions are called
or declared with no space before the opening parenthesis. That is, "function()" should become "function ()". I know it's a minor point, but it makes code much easier to read when it's all in the same style.Quoted 10 lines · Franz Hsieh (via Colin Watson)
(quoted diff) +10
-0+static struct +{ + char *name; + int key; +} function_key_aliases[] = + { + {"f1", GRUB_TERM_KEY_F1}, + {"f2", GRUB_TERM_KEY_F2}, + {"f3", GRUB_TERM_KEY_F3}, + {"f4", GRUB_TERM_KEY_F4},Review
Quoted 10 lines
(quoted diff) +10
-0+ {"f5", GRUB_TERM_KEY_F5}, + {"f6", GRUB_TERM_KEY_F6}, + {"f7", GRUB_TERM_KEY_F7}, + {"f8", GRUB_TERM_KEY_F8}, + {"f9", GRUB_TERM_KEY_F9}, + {"f10", GRUB_TERM_KEY_F10}, + {"f11", GRUB_TERM_KEY_F11}, + {"f12", GRUB_TERM_KEY_F12}, + }; +Quoted 7 lines
This is essentially a copy of
hotkey_aliasesfromgrub-core/commands/menuentry.c, and there's duplicated lookup code as well. Can you find any way to share it? Since we certainly don't want to put this in the kernel, and neither the sleep module nor the normal module really ought to depend on the other, I suspect that doing so would require a new module for shared menu code, which may well be overkill for this, but it's worth a look.I also agree to remove duplicate code, but seems not easy to do it unless
we have a shared module, right? Well it would take me some time to evaluate.Quoted 31 lines
At the very least it would be a good idea to bring the contents of this structure into sync with
hotkey_aliasesand add comments to encourage developers to keep them that way.I think we should also call this kind of thing simply "hotkey" consistently across the code, rather than it sometimes being "
function_key" or "fnkey".Review
Quoted 7 lines
(quoted diff) +7
-0+ if (key == fnkey) + { + char hotkey[32] = {0}; + grub_snprintf(hotkey, 32, "%d", key); + grub_env_set("hotkey", (char*)&hotkey); + return 1; + }We've generally tried to get rid of this kind of static allocation. Use
grub_xasprintfinstead:if (key == fnkey) { char *hotkey = grub_xasprintf ("%d", key); grub_env_set ("hotkey", hotkey); grub_free (hotkey); return 1; }Quoted 4 lines
grub-core/normal/menu.c line 104
Quoted 2 lines
grub-core/normal/menu.c +2
-0+int +grub_menu_get_hotkey (void )This function is only used in this file, so it should be static.
These idea are good and I will do these changes in my patch.
Quoted 7 lines
Rather than having to configure this explicitly, I have an alternative suggestion, which ties into my earlier suggestion of making the hotkey code a bit more shared. Why not have sleep --interruptible look up the hotkeys configured in the menu and automatically honour any of those? That way you wouldn't have to configure hotkeys in two places (grub.cfg and
/etc/default/grub). Plus, I'm always more comfortable with patches that don't require adding configuration options.Agree with Colin's points and I will update the patch.
By the way I would like to combine --function-key and --interruptible. I think
it is a simple way that sleep.mod always checks ESC for interrupt and f1~f12 for the
hotkey.Thanks for your reviews and if there is any good suggestion, please feel free to tell me.
Regards,
Franz Hsieh_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 2 lines · Franz Hsieh
I don't know if l lose any update from you. Would you give me comments
about the latest hotkey patch?
Vladimir and I talked about this on IRC today. We share a dislike for the hardcoded hotkey names. Between us, we came up with a better plan:
* The simplest way to work out what hotkeys to honour is to introspect the menu structure itself. However, this can only be done after all the top-level commands in grub.cfg have been executed, so it can't be done in the "sleep" command.
* There's nothing particular that says that we have to implement the hidden timeout in a "sleep" command, although we have to take some care to ensure configuration file compatibility with older modules. Since the main timeout is implemented in normal.mod, it makes some sense for the hidden timeout to go there too, where we can get at the menu structure.
* The simplest way to arrange for configuration file compatibility is to add a new "hiddentimeout" command that sets a "hidden_timeout" environment variable; we could also set the environment variable directly, but having a command allows us to detect the absence of that command and infer that we need to fall back to the old mechanism.
Here's a candidate patch. This does duplicate "sleep" a little bit, but it has the great advantages of not duplicating the list of valid hotkeys and of only honouring hotkeys that are associated with menu entries.
Add a new "hiddentimeout" command. If this is used, then the menu will use a hidden timeout much as was previously done with "sleep --interruptible", except that pressing any hotkeys associated with menu entries will boot the corresponding menu entry immediately.
--- ChangeLog | 7 ++ docs/grub.texi | 39 ++++++-- grub-core/Makefile.core.def | 5 ++ grub-core/commands/hiddentimeout.c | 68 ++++++++++++++ grub-core/normal/menu.c | 177 ++++++++++++++++++++++++++++++++----- util/grub.d/00_header.in | 6 +- 6 files changed, 271 insertions(+), 31 deletions(-) create mode 100644 grub-core/commands/hiddentimeout.c
ChangeLog +7 -0
@@ -1,3 +1,10 @@ +2013-11-27 Colin Watson <[email protected]> + + Add a new "hiddentimeout" command. If this is used, then the menu + will use a hidden timeout much as was previously done with "sleep + --interruptible", except that pressing any hotkeys associated with + menu entries will boot the corresponding menu entry immediately. + 2013-11-27 Vladimir Serbinenko <[email protected]> Eliminate variable length arrays in grub_vsnprintf_real.
docs/grub.texi +32 -7
@@ -1299,13 +1299,19 @@ immediately without displaying the menu, or to @samp{-1} to wait indefinitely. @item GRUB_HIDDEN_TIMEOUT -Wait this many seconds for @key{ESC} to be pressed before displaying the menu. -If no @key{ESC} is pressed during that time, display the menu for the number of -seconds specified in GRUB_TIMEOUT before booting the default entry. We expect -that most people who use GRUB_HIDDEN_TIMEOUT will want to have GRUB_TIMEOUT set -to @samp{0} so that the menu is not displayed at all unless @key{ESC} is -pressed. -Unset by default. +Wait this many seconds for @key{ESC} or a hotkey associated with a menu +entry to be pressed before displaying the menu. If @key{ESC} is pressed, +display the menu and wait for input according to @samp{GRUB_TIMEOUT}. If a +hotkey is pressed, boot the associated menu entry immediately. If the +timeout expires before either of these happens, display the menu for the +number of seconds specified in @samp{GRUB_TIMEOUT} before booting the +default entry. + +We expect that most people who use @samp{GRUB_HIDDEN_TIMEOUT} will want to +have @samp{GRUB_TIMEOUT} set to @samp{0} so that the menu is not displayed +at all unless @key{ESC} is pressed. + +This option is unset by default. @item GRUB_HIDDEN_TIMEOUT_QUIET In conjunction with @samp{GRUB_HIDDEN_TIMEOUT}, set this to @samp{true} to
@@ -3736,6 +3742,7 @@ you forget a command, you can run the command @command{help} * halt:: Shut down your computer * hashsum:: Compute or check hash checksum * help:: Show help messages +* hiddentimeout:: Configure the hidden menu timeout * initrd:: Load a Linux initrd * initrd16:: Load a Linux initrd (16-bit mode) * insmod:: Insert a module
@@ -4243,6 +4250,24 @@ about each of the commands whose names begin with those @var{patterns}. @end deffn +@node hiddentimeout +@subsection hiddentimeout + +@deffn Command hiddentimeout [@option{--visible-timeout} timeout] timeout +Configure the @samp{normal} module (@pxref{normal}) to wait @var{timeout} +seconds for @key{ESC} or a hotkey associated with a menu entry to be pressed +before displaying the menu. If @key{ESC} is pressed, display the menu and +wait for input according to the value of the @samp{timeout} variable +(@pxref{timeout}). If a hotkey is pressed, boot the associated menu entry +immediately. If the timeout expires before either of these happens, display +the menu for the number of seconds specified in the @samp{timeout} variable +before booting the default entry. + +If the @option{--visible-timeout} option is given, then configure the +@samp{normal} module to set the @samp{timeout} variable to its value if the +timeout expires without any of the recognised keys being pressed. +@end deffn + @node initrd @subsection initrd
grub-core/Makefile.core.def +5 -0
@@ -2247,3 +2247,8 @@ module = { name = progress; common = lib/progress.c; }; + +module = { + name = hiddentimeout; + common = commands/hiddentimeout.c; +};
grub-core/commands/hiddentimeout.c new file +68 -0
68 lines not on this page · raw message
grub-core/normal/menu.c +155 -22
220 lines not on this page · raw message
util/grub.d/00_header.in +4 -2
@@ -289,8 +289,10 @@ make_timeout () verbose=" --verbose" fi cat << EOF -if sleep$verbose --interruptible ${1} ; then - set timeout=${2} +if ! hiddentimeout$verbose --visible-timeout=${2} ${1} ; then + if sleep$verbose --interruptible ${1} ; then + set timeout=${2} + fi fi EOF else
Signature · 4 lines
1.8.4.4 -- Colin Watson [[email protected]]
Following discussion with Vladimir on IRC, here's another attempt. The preferred user-facing configuration mechanism is now simpler, although some unfortunate compatibility code is required to make all this work.
Revamp hidden timeout handling
Add a new timeout_style environment variable and a corresponding GRUB_TIMEOUT_STYLE configuration key for grub-mkconfig. This controls hidden-timeout handling more simply than the previous arrangements, and pressing any hotkeys associated with menu entries during the hidden timeout will now boot the corresponding menu entry immediately.
GRUB_HIDDEN_TIMEOUT=<non-empty> + GRUB_TIMEOUT=<non-zero> now generates a warning, and if it shows the menu it will do so as if the second timeout were not present. Other combinations are translated into reasonable equivalents.
--- ChangeLog | 14 ++++ docs/grub.texi | 57 ++++++++++++--- grub-core/normal/main.c | 2 +- grub-core/normal/menu.c | 175 +++++++++++++++++++++++++++++++++++++++++------ util/grub-mkconfig.in | 1 + util/grub.d/00_header.in | 35 +++++++++- 6 files changed, 251 insertions(+), 33 deletions(-)
ChangeLog +14 -0
@@ -1,3 +1,17 @@ +2013-11-28 Colin Watson <[email protected]> + + Add a new timeout_style environment variable and a corresponding + GRUB_TIMEOUT_STYLE configuration key for grub-mkconfig. This + controls hidden-timeout handling more simply than the previous + arrangements, and pressing any hotkeys associated with menu entries + during the hidden timeout will now boot the corresponding menu entry + immediately. + + GRUB_HIDDEN_TIMEOUT=<non-empty> + GRUB_TIMEOUT=<non-zero> now + generates a warning, and if it shows the menu it will do so as if + the second timeout were not present. Other combinations are + translated into reasonable equivalents. + 2013-11-27 Vladimir Serbinenko <[email protected]> Eliminate variable length arrays in grub_vsnprintf_real.
docs/grub.texi +49 -8
84 lines not on this page · raw message
grub-core/normal/main.c +1 -1
@@ -523,7 +523,7 @@ static const char *features[] = {"feature_chainloader_bpb" ,"feature_ntldr" ,"feature_platform_search_hint" ,"feature_default_font_path" ,"feature_all_video_module" ,"feature_menuentry_id" ,"feature_menuentry_options" ,"feature_200_final" , -"feature_nativedisk_cmd" +"feature_nativedisk_cmd" ,"feature_timeout_style" };GRUB_MOD_INIT (normal)
grub-core/normal/menu.c +153 -22
219 lines not on this page · raw message
util/grub-mkconfig.in +1 -0
@@ -186,6 +186,7 @@ export GRUB_DEFAULT \ GRUB_HIDDEN_TIMEOUT \ GRUB_HIDDEN_TIMEOUT_QUIET \ GRUB_TIMEOUT \ + GRUB_TIMEOUT_STYLE \ GRUB_DEFAULT_BUTTON \ GRUB_HIDDEN_TIMEOUT_BUTTON \ GRUB_TIMEOUT_BUTTON \
util/grub.d/00_header.in +33 -2
@@ -282,14 +282,45 @@ fi make_timeout () { - if [ "x${1}" != "x" ] ; then + if [ "x${GRUB_TIMEOUT_STYLE}" != "x" ] ; then + cat << EOF +if [ x\$feature_timeout_style = xy ] ; then + set timeout_style=${GRUB_TIMEOUT_STYLE} + set timeout=${2} +EOF + if [ "x${GRUB_TIMEOUT_STYLE}" != "xmenu" ] ; then + # Fallback hidden-timeout code in case the timeout_style feature + # is unavailable. Note that we now ignore GRUB_HIDDEN_TIMEOUT + # and take the hidden-timeout from GRUB_TIMEOUT instead. + if [ "x${GRUB_TIMEOUT_STYLE}" = "xhidden" ] ; then + verbose= + else + verbose=" --verbose" + fi + cat << EOF +elif sleep$verbose --interruptible ${2} ; then + set timeout=0 +EOF + fi + cat << EOF +fi +EOF + elif [ "x${1}" != "x" ] ; then + if [ "x${2}" != "x0" ] ; then + grub_warn "$(gettext "Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.")" + fi if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then verbose= + style="hidden" else verbose=" --verbose" + style="countdown" fi cat << EOF -if sleep$verbose --interruptible ${1} ; then +if [ x\$feature_timeout_style = xy ] ; then + set timeout_style=$style + set timeout=${1} +elif sleep$verbose --interruptible ${1} ; then set timeout=${2} fi EOF
Signature · 1 line
1.8.4.4
Quoted 18 lines · Colin Watson
Following discussion with Vladimir on IRC, here's another attempt. The preferred user-facing configuration mechanism is now simpler, although some unfortunate compatibility code is required to make all this work.
Revamp hidden timeout handling
Add a new
timeout_styleenvironment variable and a correspondingGRUB_TIMEOUT_STYLEconfiguration key for grub-mkconfig. This controls hidden-timeout handling more simply than the previous arrangements, and pressing any hotkeys associated with menu entries during the hidden timeout will now boot the corresponding menu entry immediately.GRUB_HIDDEN_TIMEOUT=<non-empty> + GRUB_TIMEOUT=<non-zero> now generates a warning, and if it shows the menu it will do so as if the second timeout were not present. Other combinations are translated into reasonable equivalents.
Quoted 5 lines
--- ChangeLog | 14 ++++ docs/grub.texi | 57 ++++++++++++--- grub-core/normal/main.c | 2 +- grub-core/normal/menu.c | 175
+++++++++++++++++++++++++++++++++++++++++------
Quoted 9 lines
util/grub-mkconfig.in | 1 + util/grub.d/00_header.in | 35 +++++++++- 6 files changed, 251 insertions(+), 33 deletions(-)ChangeLog +0
-0
ChangeLog line 6
Quoted 6 lines
ChangeLog +6
-0@@ -1,3 +1,17 @@ +2013-11-28 Colin Watson <[email protected]> + + Add a new timeout_style environment variable and a corresponding + GRUB_TIMEOUT_STYLE configuration key for grub-mkconfig. This + controls hidden-timeout handling more simply than the previous + arrangements, and pressing any hotkeys associated with menu
entries
ChangeLog line 7
Quoted 1 line
ChangeLog +1
-0+ during the hidden timeout will now boot the corresponding menu
entry
docs/grub.texi a key is pressed. The default is @samp{5}. Set
Quoted 15 lines
ChangeLog +7
-0+ immediately. + + GRUB_HIDDEN_TIMEOUT=<non-empty> + GRUB_TIMEOUT=<non-zero> now + generates a warning, and if it shows the menu it will do so as if + the second timeout were not present. Other combinations are + translated into reasonable equivalents. + 2013-11-27 Vladimir Serbinenko <[email protected]> Eliminate variable length arrays in grub_vsnprintf_real.docs/grub.texi +0
-0@@ -1298,19 +1298,46 @@ a key is pressed. The default is @samp{5}. Set
to @samp{0} to boot
Quoted 4 lines
docs/grub.texi +1
-0immediately without displaying the menu, or to @samp{-1} to wait indefinitely. +If @samp{GRUB_TIMEOUT_STYLE} is set to @samp{countdown} or @samp{hidden},
docs/grub.texi a key is pressed. The default is @samp{5}. Set to @samp{0} to boot
Quoted 10 lines
docs/grub.texi +10
-0+the timeout is instead counted before the menu is displayed. + +@item GRUB_TIMEOUT_STYLE +If this option is unset or set to @samp{menu}, then GRUB will display the +menu and then wait for the timeout set by @samp{GRUB_TIMEOUT} to expire +before booting the default entry. Pressing a key interrupts the timeout. + +If this option is set to @samp{countdown} or @samp{hidden}, then, before +displaying the menu, GRUB will wait for the timeout set by +@samp{GRUB_TIMEOUT} to expire. If @key{ESC} is pressed during that
time, it
docs/grub.texi a key is pressed. The default is @samp{5}. Set · line 1312
Quoted 1 line
docs/grub.texi +1
-0+will display the menu and wait for input according to
@samp{GRUB_TIMEOUT}.
docs/grub.texi a key is pressed. The default is @samp{5}. Set · line 1314
Quoted 2 lines
docs/grub.texi +2
-0+If a hotkey associated with a menu entry is pressed, it will boot the +associated menu entry immediately. If the timeout expires before either
of
docs/grub.texi a key is pressed. The default is @samp{5}. Set · line 1315
Quoted 1 line
docs/grub.texi +1
-0+these happens, it will display the menu.
What you describe here doesn‘t serm what code is doing. Copypaste error?
docs/grub.texi a key is pressed. The default is @samp{5}. Set to @samp{0} to boot
Quoted 5 lines
In the @samp{countdown} case, it
docs/grub.texi +2
-1+will show a one-line indication of the remaining time. + @item GRUB_HIDDEN_TIMEOUT -Wait this many seconds for @key{ESC} to be pressed before displaying the
menu.
Quoted 1 line
-If no @key{ESC} is pressed during that time, display the menu for the
number of
Quoted 1 line
-seconds specified in
GRUB_TIMEOUTbefore booting the default entry. We
expect
Quoted 1 line
-that most people who use
GRUB_HIDDEN_TIMEOUTwill want to have
GRUB_TIMEOUT set
docs/grub.texi a key is pressed. The default is @samp{5}. Set to @samp{0} to boot
Quoted 4 lines
docs/grub.texi +1
-3-to @samp{0} so that the menu is not displayed at all unless @key{ESC} is -pressed. -Unset by default. +Wait this many seconds before displaying the menu. If @key{ESC} is
pressed
Quoted 2 lines
+during that time, display the menu and wait for input according to +@samp{GRUB_TIMEOUT}. If a hotkey associated with a menu entry is
pressed,
Quoted 1 line
+boot the associated menu entry immediately. If the timeout expires
before
docs/grub.texi a key is pressed. The default is @samp{5}. Set to @samp{0} to boot
Quoted 13 lines
docs/grub.texi +10
-0+either of these happens, display the menu for the number of seconds +specified in @samp{GRUB_TIMEOUT} before booting the default entry. + +If you set @samp{GRUB_HIDDEN_TIMEOUT}, you should also set +@samp{GRUB_TIMEOUT=0} so that the menu is not displayed at all unless +@key{ESC} is pressed. + +This option is unset by default, and is deprecated in favour of the less +confusing @samp{GRUB_TIMEOUT_STYLE=countdown} or +@samp{GRUB_TIMEOUT_STYLE=hidden}. @item GRUB_HIDDEN_TIMEOUT_QUIET In conjunction with @samp{GRUB_HIDDEN_TIMEOUT}, set this to @samp{true}
to
Quoted 1 line
suppress the verbose countdown while waiting for a key to be pressed
before
docs/grub.texi keyboard input before booting the default menu
Quoted 17 lines
docs/grub.texi +5
-1-displaying the menu. Unset by default. +displaying the menu. + +This option is unset by default, and is deprecated in favour of the less +confusing @samp{GRUB_TIMEOUT_STYLE=countdown}. @item GRUB_DEFAULT_BUTTON @itemx GRUB_TIMEOUT_BUTTON@@ -3030,6 +3057,7 @@ These variables have special meaning to GRUB. * superusers:: * theme:: * timeout:: +* timeout_style:: @end menu@@ -3462,10 +3490,23 @@ keyboard input before booting the default menu
entry. A timeout of @samp{0}
docs/grub.texi keyboard input before booting the default menu · line 3490
Quoted 1 line
docs/grub.texi +0
-0means to boot the default entry immediately without displaying the menu;
a
docs/grub.texi keyboard input before booting the default menu entry. A timeout of @samp{0}
Quoted 3 lines
docs/grub.texi +1
-0timeout of @samp{-1} (or unset) means to wait indefinitely. +If @samp{timeout_style} (@pxref{timeout_style}) is set to
@samp{countdown}
docs/grub.texi keyboard input before booting the default menu entry. A timeout of @samp{0}
Quoted 11 lines
docs/grub.texi +7
-0+or @samp{hidden}, the timeout is instead counted before the menu is +displayed. + This variable is often set by @samp{GRUB_TIMEOUT} or @samp{GRUB_HIDDEN_TIMEOUT} (@pxref{Simple configuration}). +@node timeout_style +@subsection timeout_style + +This variable may be set to @samp{menu}, @samp{countdown}, or
@samp{hidden}
Quoted 13 lines
docs/grub.texi +5
-0+to control the way in which the timeout (@pxref{timeout}) interacts with +displaying the menu. See the documentation of @samp{GRUB_TIMEOUT_STYLE} +(@pxref{Simple configuration}) for details. + + @node Environment block @section The GRUB environment blockgrub-core/normal/main.c +0
-0
grub-core/normal/main.c static const char *features[] = { · line 523
Quoted 1 line
grub-core/normal/main.c +0
-0@@ -523,7 +523,7 @@ static const char *features[] = { "feature_chainloader_bpb", "feature_ntldr",
"feature_platform_search_hint",
grub-core/normal/main.c static const char *features[] = { · line 525
Quoted 2 lines
grub-core/normal/main.c +0
-0"feature_default_font_path" ,"feature_all_video_module" , "feature_menuentry_id", "feature_menuentry_options",
"feature_200_final",
Quoted 33 lines
grub-core/normal/main.c +1
-1- "feature_nativedisk_cmd" + "feature_nativedisk_cmd", "feature_timeout_style" };GRUB_MOD_INIT (normal)grub-core/normal/menu.c +16
-0@@ -40,6 +40,22 @@grub_err_t (*grub_gfxmenu_try_hook) (int entry,grub_menu_t menu,int nested) =NULL ; +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 } +}; +/* Wait until the user pushes any key so that the user can see what happened. */ void
grub-core/normal/menu.c grub_menu_get_entry (grub_menu_t menu, int no) · line 89
Quoted 4 lines
grub-core/normal/menu.c +1
-0@@ -70,6 +86,38 @@ grub_menu_get_entry (grub_menu_t menu, int no)return e; } +/* Get the index of a menu entry associated with a given hotkey, or -1.
*/
Quoted 5 lines
grub-core/normal/menu.c +5
-0+static int +get_entry_index_by_hotkey (grub_menu_t menu,int hotkey) +{ +grub_menu_entry_t entry; +int i;
grub-core/normal/menu.c grub_menu_get_entry (grub_menu_t menu, int no)
Quoted 10 lines
grub-core/normal/menu.c +10
-0+ +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
grub-core/normal/menu.c grub_menu_get_entry (grub_menu_t menu, int no)
Quoted 10 lines
grub-core/normal/menu.c +10
-0+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" ); + if (val) + for (style_name = timeout_style_names; style_name->name;
style_name++)
grub-core/normal/menu.c run_menu (grub_menu_t menu, int nested, int
Quoted 44 lines
grub-core/normal/menu.c +33
-0+if (grub_strcmp (style_name->name, val) ==0 ) +return style_name->style; + +return TIMEOUT_STYLE_MENU ; +} +/* Return the current timeout. If the variable "timeout" is not set or invalid, return -1. */ int @@ -488,6 +536,33 @@ get_entry_number (grub_menu_t menu, const char *name)return entry; } +/* 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 (); +} +#define GRUB_MENU_PAGE_SIZE 10/* Show the menu and handle menu entry selection. Returns the menu entry @@ -502,6 +577,7 @@ run_menu (grub_menu_t menu, int nested, int
*auto_boot)
grub-core/normal/menu.c run_menu (grub_menu_t menu, int nested, int
Quoted 8 lines
grub-core/normal/menu.c +1
-0grub_uint64_t saved_time;int default_entry, current_entry;int timeout; +enum timeout_style timeout_style; default_entry =get_entry_number (menu,"default" );@@ -510,8 +586,71 @@ run_menu (grub_menu_t menu, int nested, int
*auto_boot)
grub-core/normal/menu.c run_menu (grub_menu_t menu, int nested, int *auto_boot)
Quoted 6 lines
grub-core/normal/menu.c +3
-0if (default_entry <0 || default_entry >= menu->size) default_entry =0 ; + timeout =grub_menu_get_timeout (); +if (timeout <0 ) +/* If there is no timeout, the "countdown" and "hidden" styles
result in
grub-core/normal/menu.c run_menu (grub_menu_t menu, int nested, int · line 592
Quoted 1 line
grub-core/normal/menu.c +1
-0+ the system doing nothing and providing no or very little
indication
grub-core/normal/menu.c run_menu (grub_menu_t menu, int nested, int · line 593
Quoted 1 line
grub-core/normal/menu.c +1
-0+ why. Technically this is what the user asked for, but it's not
very
grub-core/normal/menu.c run_menu (grub_menu_t menu, int nested, int · line 594
Quoted 1 line
grub-core/normal/menu.c +1
-0+ useful and likely to be a source of confusion, so we disallow
this. */
Quoted 7 lines
grub-core/normal/menu.c +7
-0+grub_env_unset ("timeout_style" ); + + timeout_style =get_timeout_style (); + +if (timeout_style ==TIMEOUT_STYLE_COUNTDOWN + || timeout_style ==TIMEOUT_STYLE_HIDDEN ) + {
grub-core/normal/menu.c run_menu (grub_menu_t menu, int nested, int *auto_boot)
Quoted 10 lines
grub-core/normal/menu.c +10
-0+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,
grub-core/normal/menu.c run_menu (grub_menu_t menu, int nested, int
Quoted 47 lines
grub-core/normal/menu.c +41
-1+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; + } + } +/* If timeout is 0, drawing is pointless (and ugly). */ -if (grub_menu_get_timeout () ==0 ) +if (timeout ==0 ) { *auto_boot =1 ;return default_entry;@@ -540,18 +679,11 @@ run_menu (grub_menu_t menu, int nested, int
*auto_boot)
grub-core/normal/menu.c run_menu (grub_menu_t menu, int nested, int
Quoted 23 lines
grub-core/normal/menu.c +4
-11if (grub_normal_exit_level)return -1 ; -if (timeout >0 ) +if (timeout >0 &&has_second_elapsed (&saved_time)) { -grub_uint64_t current_time; - - current_time =grub_get_time_ms (); -if (current_time - saved_time >=1000 ) - { - timeout--; -grub_menu_set_timeout (timeout); - saved_time = current_time; -menu_print_timeout (timeout); - } + timeout--; +grub_menu_set_timeout (timeout); +menu_print_timeout (timeout); }if (timeout ==0 )@@ -653,16 +785,15 @@ run_menu (grub_menu_t menu, int nested, int
*auto_boot)
Quoted 30 lines
grub-core/normal/menu.c +9
-10default : { -grub_menu_entry_t entry; -int i; -for (i =0 , entry = menu->entry_list; i < menu->size; - i++, entry = entry->next) -if (entry->hotkey == c) - { -menu_fini (); - *auto_boot =0 ; -return i; - } +int entry; + + entry =get_entry_index_by_hotkey (menu, c); +if (entry >=0 ) + { +menu_fini (); + *auto_boot =0 ; +return entry; + } }break ; }util/grub-mkconfig.in +0
-0
util/grub-mkconfig.in export GRUB_DEFAULT \ · line 189
Quoted 4 lines
util/grub-mkconfig.in +1
-0@@ -186,6 +186,7 @@ export GRUB_DEFAULT \ GRUB_HIDDEN_TIMEOUT \ GRUB_HIDDEN_TIMEOUT_QUIET \ GRUB_TIMEOUT \ + GRUB_TIMEOUT_STYLE \
you need button variant as well
Quoted 10 lines
util/grub-mkconfig.in +0
-0GRUB_DEFAULT_BUTTON \ GRUB_HIDDEN_TIMEOUT_BUTTON \ GRUB_TIMEOUT_BUTTON \util/grub.d/00_header.in +0
-0@@ -282,14 +282,45 @@ fi make_timeout ()
util/grub.d/00_header.in fi · line 292
Quoted 10 lines
util/grub.d/00_header.in +8
-1{ - if [ "x${1}" != "x" ] ; then + if [ "x${GRUB_TIMEOUT_STYLE}" != "x" ] ; then + cat << EOF +if [ x\$feature_timeout_style = xy ] ; then + set timeout_style=${GRUB_TIMEOUT_STYLE} + set timeout=${2} +EOF + if [ "x${GRUB_TIMEOUT_STYLE}" != "xmenu" ] ; then + # Fallback hidden-timeout code in case the timeout_style
feature
Quoted 8 lines
util/grub.d/00_header.in +8
-0+ # is unavailable. Note that we now ignore GRUB_HIDDEN_TIMEOUT + # and take the hidden-timeout from GRUB_TIMEOUT instead. + if [ "x${GRUB_TIMEOUT_STYLE}" = "xhidden" ] ; then + verbose= + else + verbose=" --verbose" + fi + cat << EOF
util/grub.d/00_header.in fi
Quoted 10 lines
util/grub.d/00_header.in +10
-0+elif sleep$verbose --interruptible ${2} ; then + set timeout=0 +EOF + fi + cat << EOF +fi +EOF + elif [ "x${1}" != "x" ] ; then + if [ "x${2}" != "x0" ] ; then + grub_warn "$(gettext "Setting GRUB_TIMEOUT to a non-zero
value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.")"
Quoted 5 lines
util/grub.d/00_header.in +2
-0+ fi if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then verbose= + style="hidden" else
util/grub.d/00_header.in fi · line 324
Quoted 10 lines
util/grub.d/00_header.in +5
-1verbose=" --verbose" + style="countdown" fi cat << EOF -if sleep$verbose --interruptible ${1} ; then +if [ x\$feature_timeout_style = xy ] ; then + set timeout_style=$style + set timeout=${1} +elif sleep$verbose --interruptible ${1} ; then set timeout=${2}
Is behaviour mismatch between both versions intentional?
I see 2 ways of handling double timeout: either not supporting at all anymore or generate old code for it. This one seems to be mix of both
Quoted 9 lines
util/grub.d/00_header.in +0
-1fi EOF --1.8.4.4
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 13 lines · Vladimir 'phcoder' Serbinenko
Quoted 10 lines · Colin Watson
docs/grub.texi +3
-0+If this option is set to @samp{countdown} or @samp{hidden}, then, before +displaying the menu, GRUB will wait for the timeout set by +@samp{GRUB_TIMEOUT} to expire. If @key{ESC} is pressed during thattime, it
+will display the menu and wait for input according to @samp{GRUB_TIMEOUT}.(quoted diff) +2
-0+If a hotkey associated with a menu entry is pressed, it will boot the +associated menu entry immediately. If the timeout expires before eitherof
+these happens, it will display the menu.What you describe here doesn‘t serm what code is doing. Copypaste error?
I must be missing something. What part of this doesn't agree with the code?
... oh, right, if the timeout expires then it will boot the default entry. I'll fix that, thanks.
Quoted 11 lines
util/grub-mkconfig.in export GRUB_DEFAULT \ · line 189
Quoted 9 lines
util/grub-mkconfig.in +1
-0@@ -186,6 +186,7 @@ export GRUB_DEFAULT \ GRUB_HIDDEN_TIMEOUT \ GRUB_HIDDEN_TIMEOUT_QUIET \ GRUB_TIMEOUT \ + GRUB_TIMEOUT_STYLE \you need button variant as well
Can you suggest a use case for that? I can understand why you might want different timeouts in the button case, just about, but not why you'd want an entirely different style of menu.
Quoted 11 lines
Quoted 11 lines
util/grub-mkconfig.in +4
-1+ fi if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then verbose= + style="hidden" else verbose=" --verbose" + style="countdown" fi cat << EOF -if sleep$verbose --interruptible ${1} ; then +if [ x\$feature_timeout_style = xy ] ; then
Quoted 8 lines
util/grub-mkconfig.in
Quoted 4 lines
util/grub-mkconfig.in +3
-0+ set timeout_style=$style + set timeout=${1} +elif sleep$verbose --interruptible ${1} ; then set timeout=${2}Is behaviour mismatch between both versions intentional?
I see 2 ways of handling double timeout: either not supporting at all anymore or generate old code for it. This one seems to be mix of both
The code is somewhat inevitably confusing, I'll agree, but I don't see the mismatch. Could you please give me an example?
Thanks,
Signature · 1 line
Colin Watson [[email protected]]
Quoted 33 lines · Colin Watson
Quoted 13 lines · Vladimir 'phcoder' Serbinenko
Quoted 10 lines · Colin Watson
docs/grub.texi +3
-0+If this option is set to @samp{countdown} or @samp{hidden}, then, before +displaying the menu, GRUB will wait for the timeout set by +@samp{GRUB_TIMEOUT} to expire. If @key{ESC} is pressed during thattime, it
+will display the menu and wait for input according to @samp{GRUB_TIMEOUT}.(quoted diff) +2
-0+If a hotkey associated with a menu entry is pressed, it will boot the +associated menu entry immediately. If the timeout expires before eitherof
+these happens, it will display the menu.What you describe here doesn‘t serm what code is doing. Copypaste error?
I must be missing something. What part of this doesn't agree with the code?
... oh, right, if the timeout expires then it will boot the default entry. I'll fix that, thanks.
Quoted 11 lines
util/grub-mkconfig.in export GRUB_DEFAULT \ · line 189
Quoted 9 lines
util/grub-mkconfig.in +1
-0@@ -186,6 +186,7 @@ export GRUB_DEFAULT \ GRUB_HIDDEN_TIMEOUT \ GRUB_HIDDEN_TIMEOUT_QUIET \ GRUB_TIMEOUT \ + GRUB_TIMEOUT_STYLE \you need button variant as well
Quoted 4 lines
Can you suggest a use case for that? I can understand why you might want different timeouts in the button case, just about, but not why you'd want an entirely different style of menu.
Normal button: normal start, hidden menu
Second button: diagnostic, show menu
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
util/grub-mkconfig.in +4
-1+ fi if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then verbose= + style="hidden" else verbose=" --verbose" + style="countdown" fi cat << EOF -if sleep$verbose --interruptible ${1} ; then +if [ x\$feature_timeout_style = xy ] ; thenQuoted 8 lines
util/grub-mkconfig.in
Quoted 4 lines
util/grub-mkconfig.in +3
-0+ set timeout_style=$style + set timeout=${1} +elif sleep$verbose --interruptible ${1} ; then set timeout=${2}Is behaviour mismatch between both versions intentional?
I see 2 ways of handling double timeout: either not supporting at all anymore or generate old code for it. This one seems to be mix of both
Quoted 3 lines
The code is somewhat inevitably confusing, I'll agree, but I don't see the mismatch. Could you please give me an example?
if both GRUB_HIDDEN_TIMEOUT and GRUB_TIMEOUT are set the part for old GRUB will replicate old behaviour while part for new GRUB would make only one timeout. To make them align it would need set timeout=-1 at last line.
Quoted 2 lines
Thanks,
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 4 lines · Colin Watson
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
Quoted 1 line · Colin Watson
+
GRUB_TIMEOUT_STYLE\
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
you need button variant as well
Can you suggest a use case for that? I can understand why you might want different timeouts in the button case, just about, but not why you'd want an entirely different style of menu.
Normal button: normal start, hidden menu
Second button: diagnostic, show menu
Oh, I'd clearly totally misunderstood how the vendor power-on button stuff works. Thanks for the cluebat. I've added GRUB_TIMEOUT_STYLE_BUTTON now.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +4
-1-if sleep$verbose --interruptible ${1} ; then +if [ x\$feature_timeout_style = xy ] ; then + set timeout_style=$style + set timeout=${1} +elif sleep$verbose --interruptible ${1} ; then set timeout=${2}Is behaviour mismatch between both versions intentional?
I see 2 ways of handling double timeout: either not supporting at all anymore or generate old code for it. This one seems to be mix of both
Quoted 7 lines
Quoted 2 lines
The code is somewhat inevitably confusing, I'll agree, but I don't see the mismatch. Could you please give me an example?
if both
GRUB_HIDDEN_TIMEOUTandGRUB_TIMEOUTare set the part for old GRUB will replicate old behaviour while part for new GRUB would make only one timeout. To make them align it would need set timeout=-1 at last line.
Ah, you're right that I was apparently trying to preserve the old behaviour in one of the branches. However, I think you've read this backwards in one place. "sleep --interruptible" returns true (i.e. 0) if and only if the timeout expires *without* being interrupted, in which case we want timeout=0, not timeout=-1. If the timeout is interrupted, then it should be fine to just fall through, on the grounds that timeout will previously have been unset.
In any case, I've fixed the inconsistency now, and taken the opportunity to remove duplication from the code.
What do you think of this version? I think this takes into account all the comments to date.
ChangeLog +14 -0
@@ -1,3 +1,17 @@ +2013-11-28 Colin Watson <[email protected]> + + Add a new timeout_style environment variable and a corresponding + GRUB_TIMEOUT_STYLE configuration key for grub-mkconfig. This + controls hidden-timeout handling more simply than the previous + arrangements, and pressing any hotkeys associated with menu entries + during the hidden timeout will now boot the corresponding menu entry + immediately. + + GRUB_HIDDEN_TIMEOUT=<non-empty> + GRUB_TIMEOUT=<non-zero> now + generates a warning, and if it shows the menu it will do so as if + the second timeout were not present. Other combinations are + translated into reasonable equivalents. + 2013-11-27 Vladimir Serbinenko <[email protected]> Eliminate variable length arrays in grub_vsnprintf_real.
docs/grub.texi +80 -23
140 lines not on this page · raw message
grub-core/normal/main.c +1 -1
@@ -523,7 +523,7 @@ static const char *features[] = {"feature_chainloader_bpb" ,"feature_ntldr" ,"feature_platform_search_hint" ,"feature_default_font_path" ,"feature_all_video_module" ,"feature_menuentry_id" ,"feature_menuentry_options" ,"feature_200_final" , -"feature_nativedisk_cmd" +"feature_nativedisk_cmd" ,"feature_timeout_style" };GRUB_MOD_INIT (normal)
grub-core/normal/menu.c +153 -22
219 lines not on this page · raw message
util/grub-mkconfig.in +2 -0
@@ -186,9 +186,11 @@ export GRUB_DEFAULT \ GRUB_HIDDEN_TIMEOUT \ GRUB_HIDDEN_TIMEOUT_QUIET \ GRUB_TIMEOUT \ + GRUB_TIMEOUT_STYLE \ GRUB_DEFAULT_BUTTON \ GRUB_HIDDEN_TIMEOUT_BUTTON \ GRUB_TIMEOUT_BUTTON \ + GRUB_TIMEOUT_STYLE_BUTTON \ GRUB_BUTTON_CMOS_ADDRESS \ GRUB_BUTTON_CMOS_CLEAN \ GRUB_DISTRIBUTOR \
util/grub.d/00_header.in +34 -8
61 lines not on this page · raw message
Thanks,
Signature · 1 line
Colin Watson [[email protected]]
В Fri, 29 Nov 2013 16:18:45 +0000
Colin Watson <[email protected]> пишет:
docs/grub.texi menu requires several fancy features of your terminal. · line 2527
Quoted 10 lines
This variable is often set by @samp{GRUB_TIMEOUT} or @samp{GRUB_HIDDEN_TIMEOUT} (@pxref{Simple configuration}).
docs/grub.texi +7
-0+Some laptop vendors provide an additional power-on button which boots +another OS. GRUB supports such buttons with the @samp{GRUB_TIMEOUT_BUTTON}, +@samp{GRUB_TIMEOUT_STYLE_BUTTON}, @samp{GRUB_DEFAULT_BUTTON}, +@samp{GRUB_HIDDEN_TIMEOUT_BUTTON} and @samp{GRUB_BUTTON_CMOS_ADDRESS} +variables in default/grub (@pxref{Simple configuration}). +@samp{GRUB_TIMEOUT_BUTTON}, @samp{GRUB_TIMEOUT_STYLE_BUTTON}, +@samp{GRUB_DEFAULT_BUTTON}, and @samp{GRUB_HIDDEN_TIMEOUT_BUTTON} are used
Please do not mention (resp. remove) deprecated options here. This falls under "endorse usage" :)
Quoted 12 lines · Andrey Borzenkov
В Fri, 29 Nov 2013 16:18:45 +0000
Colin Watson <[email protected]> пишет:docs/grub.texi menu requires several fancy features of your terminal. · line 2527
Quoted 7 lines
docs/grub.texi +7
-0+Some laptop vendors provide an additional power-on button which boots +another OS. GRUB supports such buttons with the @samp{GRUB_TIMEOUT_BUTTON}, +@samp{GRUB_TIMEOUT_STYLE_BUTTON}, @samp{GRUB_DEFAULT_BUTTON}, +@samp{GRUB_HIDDEN_TIMEOUT_BUTTON} and @samp{GRUB_BUTTON_CMOS_ADDRESS} +variables in default/grub (@pxref{Simple configuration}). +@samp{GRUB_TIMEOUT_BUTTON}, @samp{GRUB_TIMEOUT_STYLE_BUTTON}, +@samp{GRUB_DEFAULT_BUTTON}, and @samp{GRUB_HIDDEN_TIMEOUT_BUTTON} are usedPlease do not mention (resp. remove) deprecated options here. This falls under "endorse usage" :)
Fixed, thanks.
Signature · 1 line
Colin Watson [[email protected]]
PATCH 1/1 document sleep command exit codes
In reply to Colin WatsonQuoted 2 lines
"sleep --interruptible" returns true (i.e. 0)if and only if the timeout expires *without* being interrupted,
This should not require digging in sources ...
--- docs/grub.texi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
docs/grub.texi +2 -1
@@ -4883,7 +4883,8 @@ Alias for @code{hashsum --hash sha512 arg @dots{}}. See command @command{hashsum @deffn Command sleep [@option{--verbose}] [@option{--interruptible}] count Sleep for @var{count} seconds. If option @option{--interruptible} is given, allow @key{ESC} to interrupt sleep. With @option{--verbose} show countdown -of remaining seconds. +of remaining seconds. Exit code is set to 0 if timeout expired and to 1 +if timeout was interrupted by @key{ESC}. @end deffn
Signature · 1 line
tg: (8ddf84b..) u/sleep-exit-code (depends on: master)
Re: [PATCH] document sleep command exit codes
Quoted 5 lines · Andrey Borzenkov
Quoted 2 lines
"sleep --interruptible" returns true (i.e. 0)if and only if the timeout expires *without* being interrupted,
This should not require digging in sources ...
Go ahead
Quoted 19 lines
--- docs/grub.texi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)docs/grub.texi +2
-1@@ -4883,7 +4883,8 @@ Alias for @code{hashsum --hash sha512 arg @dots{}}. See command @command{hashsum @deffn Command sleep [@option{--verbose}] [@option{--interruptible}] count Sleep for @var{count} seconds. If option @option{--interruptible} is given, allow @key{ESC} to interrupt sleep. With @option{--verbose} show countdown -of remaining seconds. +of remaining seconds. Exit code is set to 0 if timeout expired and to 1 +if timeout was interrupted by @key{ESC}. @end deffn
В Thu, 28 Nov 2013 11:04:28 +0000
Colin Watson <[email protected]> пишет:
Quoted 15 lines · Vladimir 'phcoder' Serbinenko
Quoted 5 lines · Colin Watson
Quoted 4 lines
docs/grub.texi +3
-0+If this option is set to @samp{countdown} or @samp{hidden}, then, before +displaying the menu, GRUB will wait for the timeout set by +@samp{GRUB_TIMEOUT} to expire. If @key{ESC} is pressed during thattime, it
Quoted 8 lines
Quoted 6 lines
+will display the menu and wait for input according to @samp{GRUB_TIMEOUT}.
(quoted diff) +2
-0+If a hotkey associated with a menu entry is pressed, it will boot the +associated menu entry immediately. If the timeout expires before eitherof
+these happens, it will display the menu.What you describe here doesn‘t serm what code is doing. Copypaste error?
Quoted 6 lines
I must be missing something. What part of this doesn't agree with the code?
... oh, right, if the timeout expires then it will boot the default entry. I'll fix that, thanks.
Not only. If you hit ESC it will not "wait for input according to GRUB_TIMEOUT" - it will stop displaying menu.
I'm not sure whether exposing menu but continuing count down is useful. We could let any other key (or specific key - SPACE?) do it.
Quoted 2 lines · Andrey Borzenkov
Not only. If you hit ESC it will not "wait for input according to
GRUB_TIMEOUT" - it will stop displaying menu.
No, that's not true in my tests. If you hit Escape while a hidden timeout is active and GRUB_TIMEOUT is non-zero, it'll display the menu.
If you can make this happen, please post a detailed test case.
Quoted 2 lines
I'm not sure whether exposing menu but continuing count down is useful. We could let any other key (or specific key - SPACE?) do it.
I don't think it's very useful, which is why it isn't available in the new GRUB_TIMEOUT + GRUB_TIMEOUT_STYLE interface; but it was exposed in the old GRUB_HIDDEN_TIMEOUT + GRUB_TIMEOUT interface so I don't want to break it entirely.
Signature · 1 line
Colin Watson [[email protected]]
В Thu, 28 Nov 2013 18:05:37 +0000
Colin Watson <[email protected]> пишет:
Quoted 7 lines · Andrey Borzenkov
Quoted 2 lines
Not only. If you hit ESC it will not "wait for input according to
GRUB_TIMEOUT" - it will stop displaying menu.No, that's not true in my tests. If you hit Escape while a hidden timeout is active and
GRUB_TIMEOUTis non-zero, it'll display the menu.
Oh, sorry for my English, I see where confusion is. I meant "it will display menu and stay there indefinitely". But documentation says "it will display the menu and wait for input according to `GRUB_TIMEOUT'" which is wrong because timeout is already canceled at this point.
Quoted 10 lines
If you can make this happen, please post a detailed test case.
Quoted 2 lines
I'm not sure whether exposing menu but continuing count down is useful. We could let any other key (or specific key - SPACE?) do it.
I don't think it's very useful, which is why it isn't available in the new
GRUB_TIMEOUT+GRUB_TIMEOUT_STYLEinterface; but it was exposed in the oldGRUB_HIDDEN_TIMEOUT+GRUB_TIMEOUTinterface so I don't want to break it entirely.
Anyway it is trivial to add if anyone complaints.
Thank you!
Quoted 6 lines · Andrey Borzenkov
В Thu, 28 Nov 2013 18:05:37 +0000
Colin Watson <[email protected]> пишет:Quoted 4 lines · Andrey Borzenkov
Quoted 2 lines
Not only. If you hit ESC it will not "wait for input according to
GRUB_TIMEOUT" - it will stop displaying menu.
Quoted 7 lines
Quoted 2 lines
No, that's not true in my tests. If you hit Escape while a hidden timeout is active and
GRUB_TIMEOUTis non-zero, it'll display the menu.Oh, sorry for my English, I see where confusion is. I meant "it will display menu and stay there indefinitely". But documentation says "it will display the menu and wait for input according to `GRUB_TIMEOUT'" which is wrong because timeout is already canceled at this point.
Ah, I see what you mean, sorry, and thanks. I've fixed that for the next version of this patch.
Signature · 1 line
Colin Watson [[email protected]]
В Thu, 28 Nov 2013 02:30:56 +0000
Colin Watson <[email protected]> пишет:
Quoted 2 lines
@item
GRUB_HIDDEN_TIMEOUT
@itemGRUB_HIDDEN_TIMEOUT_QUIET
I suggest removing them from user visible documentation and leaving only as compatibility options in grub-mkconfig. No reason do endorse their usage ("deprecated" is usually was nobody pays attention to).
Quoted 8 lines · Andrey Borzenkov
В Thu, 28 Nov 2013 02:30:56 +0000
Colin Watson <[email protected]> пишет:Quoted 2 lines
@item
GRUB_HIDDEN_TIMEOUT
@itemGRUB_HIDDEN_TIMEOUT_QUIETI suggest removing them from user visible documentation and leaving only as compatibility options in grub-mkconfig. No reason do endorse their usage ("deprecated" is usually was nobody pays attention to).
My concern is that they will probably hang around in people's configurations for some time and I would like the documentation to tell users what these mysterious things mean.
As a compromise, perhaps we could move them to a separate page?
Signature · 1 line
Colin Watson [[email protected]]
В Thu, 28 Nov 2013 18:06:44 +0000
Colin Watson <[email protected]> пишет:
Quoted 10 lines · Andrey Borzenkov
Quoted 8 lines
В Thu, 28 Nov 2013 02:30:56 +0000
Colin Watson <[email protected]> пишет:Quoted 2 lines
@item
GRUB_HIDDEN_TIMEOUT
@itemGRUB_HIDDEN_TIMEOUT_QUIETI suggest removing them from user visible documentation and leaving only as compatibility options in grub-mkconfig. No reason do endorse their usage ("deprecated" is usually was nobody pays attention to).
Quoted 6 lines
My concern is that they will probably hang around in people's configurations for some time and I would like the documentation to tell users what these mysterious things mean.
As a compromise, perhaps we could move them to a separate page?
May be collect all deprecated options at the end of list with heading like "The following options are still accepted for compatibility with existing configurations but should not be used in new setup anymore" or similar.
And BTW, we probably need to start collecting NEWS topics - this is excellent candidate for inclusion :)
В Wed, 11 Sep 2013 14:18:04 +0100
Colin Watson <[email protected]> пишет:
Quoted 6 lines
grub-core/normal/menu.c +5
-0+int +grub_menu_get_hotkey (void ) +{ +char *val; +int hotkey;
grub-core/normal/menu.c line 120
Quoted 10 lines
grub-core/normal/menu.c +10
-0+ + val =grub_env_get ("hotkey" ); +if (! val) +return -1 ; + +grub_error_push (); + + hotkey = (int )grub_strtoul (val,0 ,10 ); + +/* If the value is invalid, unset the variable. */
Why only if invalid? This is one time event which should be reset as soon as it is consumed.
Actually I'm not sure if user visible environment variable is needed at all - just make it a global variable in normal.mod.
Quoted 11 lines · Andrey Borzenkov
В Wed, 11 Sep 2013 14:18:04 +0100
Quoted 10 lines
grub-core/normal/menu.c +10
-0+int +grub_menu_get_hotkey (void ) +{ +char *val; +int hotkey; + + val =grub_env_get ("hotkey" ); +if (! val) +return -1 ; +
Quoted 8 lines
grub-core/normal/menu.c line 120
Quoted 5 lines
grub-core/normal/menu.c +5
-0+grub_error_push (); + + hotkey = (int )grub_strtoul (val,0 ,10 ); + +/* If the value is invalid, unset the variable. */ Why only if invalid? This is one time event which should be reset as soon as it is consumed.
Agreed.
Quoted 2 lines
Actually I'm not sure if user visible environment variable is needed at all - just make it a global variable in normal.mod.
This goes back to what I was saying about sleep.mod not being sensibly able to depend on normal.mod, so in order to do this kind of this we either need shared code in the kernel (best avoided) or a new module common to both.
(Or we could do something like exporting grub_dl_resolve_symbol so that we have dlsym-like functionality. But this is starting to look rather baroque just for the sake of avoiding a transient environment variable, IMO.)
Signature · 1 line
Colin Watson [[email protected]]