From nobody@FreeBSD.org  Tue Oct  9 18:27:37 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 69560DD2
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  9 Oct 2012 18:27:37 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 516508FC18
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  9 Oct 2012 18:27:37 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q99IRbh7038739
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 9 Oct 2012 18:27:37 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q99IRb1i038738;
	Tue, 9 Oct 2012 18:27:37 GMT
	(envelope-from nobody)
Message-Id: <201210091827.q99IRb1i038738@red.freebsd.org>
Date: Tue, 9 Oct 2012 18:27:37 GMT
From: Devin Teske <dteske@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Non-default boot_verbose=YES in loader.conf(5) not displayed by beastie menu
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         172529
>Category:       bin
>Synopsis:       [patch] Non-default boot_verbose=YES in loader.conf(5) not displayed by beastie menu
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dteske
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          maintainer-update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 09 22:30:13 UTC 2012
>Closed-Date:    Tue Apr 01 00:25:39 UTC 2014
>Last-Modified:  Tue Apr 01 00:25:39 UTC 2014
>Originator:     Devin Teske
>Release:        FreeBSD 9.0-RELEASE i386
>Organization:
FIS Global, Inc. -- VICOR Business Unit (VBU)
>Environment:
FreeBSD scribe9.vicor.com 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:15:25 UTC 2012     root@obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
Since the introduction of the new advanced boot menu (r222417), options like "boot verbose", "single user mode", "ACPI" and more are now stateful boolean menuitems rather than direct action-items.

A short-coming in this new menu system is that when a user sets a non-default value in loader.conf(5), this non-default state is not reflected in the menu -- leading to confusion as to whether the option was taking effect or not.

If nobody objects, I will commit the attached patch.txt to add dynamic menuitem constructors _and_ the necessary Forth callbacks to initialize these menuitems.

Once applied, the aforementioned menuitems will adhere to loader.conf(5) settings.
>How-To-Repeat:
Add boot_verbose="YES" to loader.conf(5) and reboot. Notice that the "Verbose" option in the beastie menu still says "Verbose... off".
>Fix:
See attached patch.txt.

Patch attached with submission follows:

Index: menu-commands.4th
===================================================================
--- menu-commands.4th	(revision 241367)
+++ menu-commands.4th	(working copy)
@@ -26,6 +26,9 @@
 
 marker task-menu-commands.4th
 
+variable kernel_state
+variable root_state
+
 : acpi_enable ( -- )
 	s" set acpi_load=YES" evaluate \ XXX deprecated but harmless
 	s" set hint.acpi.0.disabled=0" evaluate
@@ -53,6 +56,13 @@ marker task-menu-commands.4th
 	TRUE \ loop menu again
 ;
 
+: init_safemode ( N -- N )
+	s" kern.smp.disabled" getenv -1 <> if
+		drop ( n c-addr -- n ) \ unused
+		toggle_menuitem ( n -- n )
+	then
+;
+
 : toggle_safemode ( N -- N TRUE )
 	toggle_menuitem
 
@@ -84,6 +94,13 @@ marker task-menu-commands.4th
 	TRUE \ loop menu again
 ;
 
+: init_singleuser ( N -- N )
+	s" boot_single" getenv -1 <> if
+		drop ( n c-addr -- n ) \ unused
+		toggle_menuitem ( n -- n )
+	then
+;
+
 : toggle_singleuser ( N -- N TRUE )
 	toggle_menuitem
 	menu-redraw
@@ -102,6 +119,13 @@ marker task-menu-commands.4th
 	TRUE \ loop menu again
 ;
 
+: init_verbose ( N -- N )
+	s" boot_verbose" getenv -1 <> if
+		drop ( n c-addr -- n ) \ unused
+		toggle_menuitem ( n -- n )
+	then
+;
+
 : toggle_verbose ( N -- N TRUE )
 	toggle_menuitem
 	menu-redraw
@@ -132,6 +156,27 @@ marker task-menu-commands.4th
 	FALSE \ exit the menu
 ;
 
+: init_cyclestate ( N K -- N )
+	over                   ( n k -- n k n )
+	s" cycle_stateN"       ( n k n -- n k n c-addr u )
+	-rot tuck 11 + c! swap ( n k n c-addr u -- n k c-addr u )
+	evaluate               ( n k c-addr u -- n k addr )
+	begin
+		tuck @  ( n k addr -- n addr k c )
+		over <> ( n addr k c -- n addr k 0|-1 )
+	while
+		rot ( n addr k -- addr k n )
+		cycle_menuitem
+		swap rot ( addr k n -- n k addr )
+	repeat
+	2drop ( n k addr -- n )
+;
+
+: init_kernel ( N -- N )
+	kernel_state @  ( n -- n k )
+	init_cyclestate ( n k -- n )
+;
+
 : cycle_kernel ( N -- N TRUE )
 	cycle_menuitem
 	menu-redraw
@@ -142,6 +187,7 @@ marker task-menu-commands.4th
 	-rot 2dup 11 + c! rot    \ replace 'N' with ASCII numeral
 	evaluate                 \ translate name into address
 	@                        \ dereference address into value
+	dup kernel_state !       \ save a copy for re-initialization
 	48 +                     \ convert to ASCII numeral
 
 	s" set kernel=${kernel_prefix}${kernel[N]}${kernel_suffix}"
@@ -152,6 +198,11 @@ marker task-menu-commands.4th
 	TRUE \ loop menu again
 ;
 
+: init_root ( N -- N )
+	root_state @    ( n -- n k )
+	init_cyclestate ( n k -- n )
+;
+
 : cycle_root ( N -- N TRUE )
 	cycle_menuitem
 	menu-redraw
@@ -162,6 +213,7 @@ marker task-menu-commands.4th
 	-rot 2dup 11 + c! rot    \ replace 'N' with ASCII numeral
 	evaluate                 \ translate name into address
 	@                        \ dereference address into value
+	dup root_state !         \ save a copy for re-initialization
 	48 +                     \ convert to ASCII numeral
 
 	s" set root=${root_prefix}${root[N]}${root_suffix}"
Index: menu.4th
===================================================================
--- menu.4th	(revision 241365)
+++ menu.4th	(working copy)
@@ -76,6 +76,16 @@ variable menu_timeout         \ determined configu
 variable menu_timeout_x       \ column position of timeout message
 variable menu_timeout_y       \ row position of timeout message
 
+\ Menu initialization status variables
+variable init_state1
+variable init_state2
+variable init_state3
+variable init_state4
+variable init_state5
+variable init_state6
+variable init_state7
+variable init_state8
+
 \ Boolean option status variables
 variable toggle_state1
 variable toggle_state2
@@ -421,6 +431,16 @@ create init_text8 255 allot
 	then
 	24 over 2 / - 9 at-xy type 
 
+	\ If $menu_init is set, evaluate it (allowing for whole menus to be
+	\ constructed dynamically -- as this function could conceivably set
+	\ the remaining environment variables to construct the menu entirely).
+	\ 
+	s" menu_init" getenv dup -1 <> if
+		evaluate
+	else
+		drop
+	then
+
 	\ Print our menu options with respective key/variable associations.
 	\ `printmenuitem' ends by adding the decimal ASCII value for the
 	\ numerical prefix to the stack. We store the value left on the stack
@@ -499,6 +519,24 @@ create init_text8 255 allot
 		dup menuacpi @ = if
 			acpimenuitem ( -- C-Addr/U | -1 )
 		else
+			\ make sure we have not already initialized this item
+			s" init_stateN"
+			-rot 2dup 10 + c! rot \ repace 'N'
+			evaluate dup @ 0= if
+				1 swap !
+
+				\ If this menuitem has an initializer, run it
+				s" menu_init[x]"
+				-rot 2dup 10 + c! rot \ replace 'x'
+				getenv dup -1 <> if
+					evaluate
+				else
+					drop
+				then
+			else
+				drop
+			then
+
 			loader_color? if
 				s" ansi_caption[x]"
 			else
@@ -917,6 +955,10 @@ create init_text8 255 allot
 		-rot 2dup 13 + c! rot	\ replace 'x'
 		unsetenv
 
+		s" menu_init[x]"	\ initializer basename
+		-rot 2dup 10 + c! rot	\ replace 'x'
+		unsetenv
+
 		s" menu_keycode[x]"	\ keycode basename
 		-rot 2dup 13 + c! rot	\ replace 'x'
 		unsetenv
@@ -959,6 +1001,10 @@ create init_text8 255 allot
 		-rot 2dup 9 + c! rot	\ replace 'N' with current iteration
 		evaluate		\ assign zero (0) to key assoc. var
 
+		s" 0 init_stateN !"	\ used by menu-create
+		-rot 2dup 12 + c! rot	\ replace 'N'
+		evaluate
+
 		1+ dup 56 >	\ increment, continue if less than 57
 	until
 	drop \ iterator
@@ -979,6 +1025,8 @@ create init_text8 255 allot
 	s" menu_optionstext" unsetenv
 	0 menuoptions !
 
+	\ clear the menu initializer
+	s" menu_init" unsetenv
 ;
 
 \ This function both unsets menu variables and visually erases the menu area
@@ -994,6 +1042,16 @@ bullet menubllt !
 10 menuY !
 5 menuX !
 
+\ Initialize our menu initialization state variables
+0 init_state1 !
+0 init_state2 !
+0 init_state3 !
+0 init_state4 !
+0 init_state5 !
+0 init_state6 !
+0 init_state7 !
+0 init_state8 !
+
 \ Initialize our boolean state variables
 0 toggle_state1 !
 0 toggle_state2 !


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->dteske 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Oct 10 00:55:21 UTC 2012 
Responsible-Changed-Why:  
Over to submitter.  (Submitter wanted public review of the patch.) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172529 

From: Devin Teske <devin.teske@fisglobal.com>
To: <bug-followup@FreeBSD.org>, Devin Teske <dteske@FreeBSD.org>
Cc: Adrian Chadd <adrian@freebsd.org>, Eitan Adler <eadler@FreeBSD.org>
Subject: Re: bin/172529: [patch] Non-default boot_verbose=YES in loader.conf(5) not displayed by beastie menu
Date: Wed, 10 Oct 2012 21:27:41 -0700

 Looks like no takers for review, so I'll quietly push forward to commit thi=
 s as maintainer-update.
 --=20
 Devin
 
 _____________
 The information contained in this message is proprietary and/or confidentia=
 l. If you are not the intended recipient, please: (i) delete the message an=
 d all copies; (ii) do not disclose, distribute or use the message in any ma=
 nner; and (iii) notify the sender immediately. In addition, please be aware=
  that any message addressed to our domain is subject to archiving and revie=
 w by persons other than the intended recipient. Thank you.

From: Devin Teske <devin.teske@fisglobal.com>
To: <bug-followup@FreeBSD.org>, <dteske@FreeBSD.org>
Cc: Adrian Chadd <adrian@freebsd.org>, Eitan Adler <eadler@FreeBSD.org>
Subject: Re: bin/172529: [patch] Non-default boot_verbose=YES in loader.conf(5) not displayed by beastie menu
Date: Thu, 11 Oct 2012 14:28:48 -0700

 --Apple-Mail=_9637A592-417D-449A-8CAE-3B83A80FA4CE
 Content-Transfer-Encoding: quoted-printable
 Content-Type: text/plain; charset="us-ascii"
 
 In my over-cautious approach to "not change any functionality," (as-per the=
  recent mailing-list thread on -arch) I neglected to actually hook-in the n=
 ew callbacks.
 
 Please find attached patch.txt that hooks-in the new functionality (require=
 d to fix the reported bug).
 --=20
 Devin
 
 _____________
 The information contained in this message is proprietary and/or confidentia=
 l. If you are not the intended recipient, please: (i) delete the message an=
 d all copies; (ii) do not disclose, distribute or use the message in any ma=
 nner; and (iii) notify the sender immediately. In addition, please be aware=
  that any message addressed to our domain is subject to archiving and revie=
 w by persons other than the intended recipient. Thank you.
 
 --Apple-Mail=_9637A592-417D-449A-8CAE-3B83A80FA4CE
 Content-Disposition: attachment; filename="patch.txt"
 Content-Type: text/plain; name="patch.txt"
 Content-Transfer-Encoding: 7bit
 
 Index: menu-commands.4th
 ===================================================================
 --- menu-commands.4th	(revision 241367)
 +++ menu-commands.4th	(working copy)
 @@ -26,6 +26,9 @@
  
  marker task-menu-commands.4th
  
 +variable kernel_state
 +variable root_state
 +
  : acpi_enable ( -- )
  	s" set acpi_load=YES" evaluate \ XXX deprecated but harmless
  	s" set hint.acpi.0.disabled=0" evaluate
 @@ -53,6 +56,13 @@
  	TRUE \ loop menu again
  ;
  
 +: init_safemode ( N -- N )
 +	s" kern.smp.disabled" getenv -1 <> if
 +		drop ( n c-addr -- n ) \ unused
 +		toggle_menuitem ( n -- n )
 +	then
 +;
 +
  : toggle_safemode ( N -- N TRUE )
  	toggle_menuitem
  
 @@ -84,6 +94,13 @@
  	TRUE \ loop menu again
  ;
  
 +: init_singleuser ( N -- N )
 +	s" boot_single" getenv -1 <> if
 +		drop ( n c-addr -- n ) \ unused
 +		toggle_menuitem ( n -- n )
 +	then
 +;
 +
  : toggle_singleuser ( N -- N TRUE )
  	toggle_menuitem
  	menu-redraw
 @@ -102,6 +119,13 @@
  	TRUE \ loop menu again
  ;
  
 +: init_verbose ( N -- N )
 +	s" boot_verbose" getenv -1 <> if
 +		drop ( n c-addr -- n ) \ unused
 +		toggle_menuitem ( n -- n )
 +	then
 +;
 +
  : toggle_verbose ( N -- N TRUE )
  	toggle_menuitem
  	menu-redraw
 @@ -132,6 +156,27 @@
  	FALSE \ exit the menu
  ;
  
 +: init_cyclestate ( N K -- N )
 +	over                   ( n k -- n k n )
 +	s" cycle_stateN"       ( n k n -- n k n c-addr u )
 +	-rot tuck 11 + c! swap ( n k n c-addr u -- n k c-addr u )
 +	evaluate               ( n k c-addr u -- n k addr )
 +	begin
 +		tuck @  ( n k addr -- n addr k c )
 +		over <> ( n addr k c -- n addr k 0|-1 )
 +	while
 +		rot ( n addr k -- addr k n )
 +		cycle_menuitem
 +		swap rot ( addr k n -- n k addr )
 +	repeat
 +	2drop ( n k addr -- n )
 +;
 +
 +: init_kernel ( N -- N )
 +	kernel_state @  ( n -- n k )
 +	init_cyclestate ( n k -- n )
 +;
 +
  : cycle_kernel ( N -- N TRUE )
  	cycle_menuitem
  	menu-redraw
 @@ -142,6 +187,7 @@
  	-rot 2dup 11 + c! rot    \ replace 'N' with ASCII numeral
  	evaluate                 \ translate name into address
  	@                        \ dereference address into value
 +	dup kernel_state !       \ save a copy for re-initialization
  	48 +                     \ convert to ASCII numeral
  
  	s" set kernel=${kernel_prefix}${kernel[N]}${kernel_suffix}"
 @@ -152,6 +198,11 @@
  	TRUE \ loop menu again
  ;
  
 +: init_root ( N -- N )
 +	root_state @    ( n -- n k )
 +	init_cyclestate ( n k -- n )
 +;
 +
  : cycle_root ( N -- N TRUE )
  	cycle_menuitem
  	menu-redraw
 @@ -162,6 +213,7 @@
  	-rot 2dup 11 + c! rot    \ replace 'N' with ASCII numeral
  	evaluate                 \ translate name into address
  	@                        \ dereference address into value
 +	dup root_state !         \ save a copy for re-initialization
  	48 +                     \ convert to ASCII numeral
  
  	s" set root=${root_prefix}${root[N]}${root_suffix}"
 Index: menu.4th
 ===================================================================
 --- menu.4th	(revision 241365)
 +++ menu.4th	(working copy)
 @@ -76,6 +76,16 @@
  variable menu_timeout_x       \ column position of timeout message
  variable menu_timeout_y       \ row position of timeout message
  
 +\ Menu initialization status variables
 +variable init_state1
 +variable init_state2
 +variable init_state3
 +variable init_state4
 +variable init_state5
 +variable init_state6
 +variable init_state7
 +variable init_state8
 +
  \ Boolean option status variables
  variable toggle_state1
  variable toggle_state2
 @@ -421,6 +431,16 @@
  	then
  	24 over 2 / - 9 at-xy type 
  
 +	\ If $menu_init is set, evaluate it (allowing for whole menus to be
 +	\ constructed dynamically -- as this function could conceivably set
 +	\ the remaining environment variables to construct the menu entirely).
 +	\ 
 +	s" menu_init" getenv dup -1 <> if
 +		evaluate
 +	else
 +		drop
 +	then
 +
  	\ Print our menu options with respective key/variable associations.
  	\ `printmenuitem' ends by adding the decimal ASCII value for the
  	\ numerical prefix to the stack. We store the value left on the stack
 @@ -499,6 +519,24 @@
  		dup menuacpi @ = if
  			acpimenuitem ( -- C-Addr/U | -1 )
  		else
 +			\ make sure we have not already initialized this item
 +			s" init_stateN"
 +			-rot 2dup 10 + c! rot \ repace 'N'
 +			evaluate dup @ 0= if
 +				1 swap !
 +
 +				\ If this menuitem has an initializer, run it
 +				s" menu_init[x]"
 +				-rot 2dup 10 + c! rot \ replace 'x'
 +				getenv dup -1 <> if
 +					evaluate
 +				else
 +					drop
 +				then
 +			else
 +				drop
 +			then
 +
  			loader_color? if
  				s" ansi_caption[x]"
  			else
 @@ -917,6 +955,10 @@
  		-rot 2dup 13 + c! rot	\ replace 'x'
  		unsetenv
  
 +		s" menu_init[x]"	\ initializer basename
 +		-rot 2dup 10 + c! rot	\ replace 'x'
 +		unsetenv
 +
  		s" menu_keycode[x]"	\ keycode basename
  		-rot 2dup 13 + c! rot	\ replace 'x'
  		unsetenv
 @@ -959,6 +1001,10 @@
  		-rot 2dup 9 + c! rot	\ replace 'N' with current iteration
  		evaluate		\ assign zero (0) to key assoc. var
  
 +		s" 0 init_stateN !"	\ used by menu-create
 +		-rot 2dup 12 + c! rot	\ replace 'N'
 +		evaluate
 +
  		1+ dup 56 >	\ increment, continue if less than 57
  	until
  	drop \ iterator
 @@ -979,6 +1025,8 @@
  	s" menu_optionstext" unsetenv
  	0 menuoptions !
  
 +	\ clear the menu initializer
 +	s" menu_init" unsetenv
  ;
  
  \ This function both unsets menu variables and visually erases the menu area
 @@ -994,6 +1042,16 @@
  10 menuY !
  5 menuX !
  
 +\ Initialize our menu initialization state variables
 +0 init_state1 !
 +0 init_state2 !
 +0 init_state3 !
 +0 init_state4 !
 +0 init_state5 !
 +0 init_state6 !
 +0 init_state7 !
 +0 init_state8 !
 +
  \ Initialize our boolean state variables
  0 toggle_state1 !
  0 toggle_state2 !
 Index: menu.rc
 ===================================================================
 --- menu.rc	(revision 241310)
 +++ menu.rc	(working copy)
 @@ -48,6 +48,7 @@
  
  set menu_caption[5]="Safe [M]ode... off"
  set toggled_text[5]="Safe [M]ode... On"
 +set menu_init[5]="init_safemode"
  set menu_command[5]="toggle_safemode"
  set menu_keycode[5]="109"
  set ansi_caption[5]="Safe [1mM[37mode... [34;1mOff[37m"
 @@ -55,6 +56,7 @@
  
  set menu_caption[6]="[S]ingle User. off"
  set toggled_text[6]="[S]ingle User. On"
 +set menu_init[6]="init_singleuser"
  set menu_command[6]="toggle_singleuser"
  set menu_keycode[6]="115"
  set ansi_caption[6]="[1mS[37mingle User. [34;1mOff[37m"
 @@ -62,6 +64,7 @@
  
  set menu_caption[7]="[V]erbose..... off"
  set toggled_text[7]="[V]erbose..... On"
 +set menu_init[7]="init_verbose"
  set menu_command[7]="toggle_verbose"
  set menu_keycode[7]="118"
  set ansi_caption[7]="[1mV[37merbose..... [34;1mOff[37m"
 
 --Apple-Mail=_9637A592-417D-449A-8CAE-3B83A80FA4CE--
State-Changed-From-To: open->patched 
State-Changed-By: dteske 
State-Changed-When: Thu Nov 15 06:10:16 UTC 2012 
State-Changed-Why:  
Committed as r241523 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172529 
State-Changed-From-To: patched->closed 
State-Changed-By: dteske 
State-Changed-When: Tue Apr 1 00:25:27 UTC 2014 
State-Changed-Why:  
Fixed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172529 
>Unformatted:
