Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Jun 2013 23:58:44 +0000 (UTC)
From:      Devin Teske <dteske@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r251236 - in head/usr.sbin/bsdconfig: . console mouse networking networking/share security share share/media share/packages startup startup/share timezone usermgmt usermgmt/share
Message-ID:  <201306012358.r51NwiFI006489@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dteske
Date: Sat Jun  1 23:58:44 2013
New Revision: 251236
URL: http://svnweb.freebsd.org/changeset/base/251236

Log:
  Improve portion of the dialog(1) API in dialog.subr responsible for
  retrieving stored data (for the --menu, --calendar, --timebox, --checklist,
  and --radiolist widgets).
  
  When we (Ron McDowell and I) developed the first version of bsdconfig, it
  used temporary files to store responses from dialog(1). That hasn't been
  true for some very long time, so the need to always store the return status
  of dialog(1) and then call some function to clean-up is long-deprecated. The
  function that used to do the clean-up was f_dialog_menutag().
  
  We really don't need f_dialog_menutag() for its originally designed purpose,
  as all dialog invocations (even when in a sub-shell) do not use temporary
  files anymore.
  
  However, we do need to keep f_dialog_menutag() around because it still fills
  the need of being able to abstract the procedure for fetching stored data
  provided by functions that display the aforementioned widgets.
  
  In re-designing f_dialog_menutag(), four important changes are made:
  
  1. Rename f_dialog_menutag() to f_dialog_menutag_fetch()
  2. Introduce the new first-argument of $var_to_set to reduce number of forks
  3. Create a corresponding f_dialog_menutag_store() to abstract the storage
  4. Offload the sanitization to a new function, f_dialog_data_sanitize()
  
  NOTE: That last one is important. Not all functions need to store their data
  for later fetching, meanwhile every invocation of dialog should be sanitized
  (as we learned early-on in the i18n-effort -- underlying libraries will spit
  warnings to stderr for bad values of $LANG and since dialog outputs its
  responses to stderr, we need to sanitize every response of these warnings).
  
  These changes greatly improve readbaility and also improve performance by
  reducing unnecessary forking.

Modified:
  head/usr.sbin/bsdconfig/bsdconfig
  head/usr.sbin/bsdconfig/console/console
  head/usr.sbin/bsdconfig/console/font
  head/usr.sbin/bsdconfig/console/keymap
  head/usr.sbin/bsdconfig/console/repeat
  head/usr.sbin/bsdconfig/console/saver
  head/usr.sbin/bsdconfig/console/screenmap
  head/usr.sbin/bsdconfig/console/ttys
  head/usr.sbin/bsdconfig/mouse/mouse
  head/usr.sbin/bsdconfig/mouse/port
  head/usr.sbin/bsdconfig/mouse/type
  head/usr.sbin/bsdconfig/networking/devices
  head/usr.sbin/bsdconfig/networking/networking
  head/usr.sbin/bsdconfig/networking/share/device.subr
  head/usr.sbin/bsdconfig/networking/share/media.subr
  head/usr.sbin/bsdconfig/networking/share/resolv.subr
  head/usr.sbin/bsdconfig/security/kern_securelevel
  head/usr.sbin/bsdconfig/security/security
  head/usr.sbin/bsdconfig/share/device.subr
  head/usr.sbin/bsdconfig/share/dialog.subr
  head/usr.sbin/bsdconfig/share/media/any.subr
  head/usr.sbin/bsdconfig/share/media/ftp.subr
  head/usr.sbin/bsdconfig/share/media/options.subr
  head/usr.sbin/bsdconfig/share/media/tcpip.subr
  head/usr.sbin/bsdconfig/share/mustberoot.subr
  head/usr.sbin/bsdconfig/share/packages/packages.subr
  head/usr.sbin/bsdconfig/startup/misc
  head/usr.sbin/bsdconfig/startup/rcadd
  head/usr.sbin/bsdconfig/startup/rcconf
  head/usr.sbin/bsdconfig/startup/rcdelete
  head/usr.sbin/bsdconfig/startup/rcvar
  head/usr.sbin/bsdconfig/startup/share/rcconf.subr
  head/usr.sbin/bsdconfig/startup/startup
  head/usr.sbin/bsdconfig/timezone/timezone
  head/usr.sbin/bsdconfig/usermgmt/groupdel
  head/usr.sbin/bsdconfig/usermgmt/groupedit
  head/usr.sbin/bsdconfig/usermgmt/groupinput
  head/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
  head/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
  head/usr.sbin/bsdconfig/usermgmt/userdel
  head/usr.sbin/bsdconfig/usermgmt/useredit
  head/usr.sbin/bsdconfig/usermgmt/userinput
  head/usr.sbin/bsdconfig/usermgmt/usermgmt

Modified: head/usr.sbin/bsdconfig/bsdconfig
==============================================================================
--- head/usr.sbin/bsdconfig/bsdconfig	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/bsdconfig	Sat Jun  1 23:58:44 2013	(r251236)
@@ -187,8 +187,8 @@ dialog_menu_main()
 	                                  \"\"         \
 	                                  $menu_list
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--clear                                 \
 		--title \"\$title\"                     \
 		--backtitle \"\$btitle\"                \
@@ -205,10 +205,11 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_data_sanitize menu_choice
+	f_dialog_menutag_store "$menu_choice"
 
 	# Only update default-item on success
-	[ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$dialog_menu"
+	[ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$menu_choice"
 
 	return $retval
 }
@@ -298,7 +299,7 @@ fi
 while :; do
 	dialog_menu_main
 	retval=$?
-	mtag=$( f_dialog_menutag )
+	f_dialog_menutag_fetch mtag
 	f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
 
 	if [ $retval -eq 2 ]; then

Modified: head/usr.sbin/bsdconfig/console/console
==============================================================================
--- head/usr.sbin/bsdconfig/console/console	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/console/console	Sat Jun  1 23:58:44 2013	(r251236)
@@ -70,8 +70,8 @@ dialog_menu_main()
 	                        \"\$hline\"            \
 	                        $menu_list
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"          \
 		--backtitle \"\$DIALOG_BACKTITLE\"  \
 		--hline \"\$hline\"                 \
@@ -84,8 +84,9 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DEFAULTITEM_$$ "$dialog_menu"
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_data_sanitize menu_choice
+	f_dialog_menutag_store "$menu_choice"
+	setvar DEFAULTITEM_$$ "$menu_choice"
 	return $retval
 }
 
@@ -115,11 +116,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	"X $msg_exit") break ;;

Modified: head/usr.sbin/bsdconfig/console/font
==============================================================================
--- head/usr.sbin/bsdconfig/console/font	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/console/font	Sat Jun  1 23:58:44 2013	(r251236)
@@ -95,8 +95,8 @@ dialog_menu_main()
 	swiss-8x8) defaultitem="e $msg_swiss";;
 	esac
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -109,7 +109,7 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -139,11 +139,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	"1 $msg_none") # Use hardware default font

Modified: head/usr.sbin/bsdconfig/console/keymap
==============================================================================
--- head/usr.sbin/bsdconfig/console/keymap	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/console/keymap	Sat Jun  1 23:58:44 2013	(r251236)
@@ -193,8 +193,8 @@ dialog_menu_main()
 		) && defaultitem=" $defaultitem"
 	fi
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -207,7 +207,7 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -237,11 +237,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	#
 	# Reverse the users choice into the variable name

Modified: head/usr.sbin/bsdconfig/console/repeat
==============================================================================
--- head/usr.sbin/bsdconfig/console/repeat	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/console/repeat	Sat Jun  1 23:58:44 2013	(r251236)
@@ -75,8 +75,8 @@ dialog_menu_main()
 	[Nn][Oo]|'') defaultitem="$msg_default";;
 	esac
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -89,7 +89,7 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -119,11 +119,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	"$msg_slow") # Slow keyboard repeat rate

Modified: head/usr.sbin/bsdconfig/console/saver
==============================================================================
--- head/usr.sbin/bsdconfig/console/saver	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/console/saver	Sat Jun  1 23:58:44 2013	(r251236)
@@ -94,8 +94,8 @@ dialog_menu_main()
 	[Nn][Oo]|'') defaultitem="d $msg_none"   ;;
 	esac
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -108,7 +108,7 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -138,11 +138,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	"1 $msg_blank") # Simply blank the screen

Modified: head/usr.sbin/bsdconfig/console/screenmap
==============================================================================
--- head/usr.sbin/bsdconfig/console/screenmap	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/console/screenmap	Sat Jun  1 23:58:44 2013	(r251236)
@@ -79,8 +79,8 @@ dialog_menu_main()
 	koi8-u2cp866u)       defaultitem="6 $msg_koi8_u_to_ibm866u"    ;;
 	esac
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -93,7 +93,7 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -123,11 +123,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	"1 $msg_none") # No screenmap, don't touch font

Modified: head/usr.sbin/bsdconfig/console/ttys
==============================================================================
--- head/usr.sbin/bsdconfig/console/ttys	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/console/ttys	Sat Jun  1 23:58:44 2013	(r251236)
@@ -83,8 +83,8 @@ dialog_menu_main()
 	                        \"\$hline\"            \
 	                        $TTY_MENU_LIST
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -96,7 +96,7 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -182,11 +182,9 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
-	[ $retval -eq 0 ] || f_die
 	[ "$mtag" = "1 $msg_none" ] && break
 
 	consterm=$( eval f_dialog_menutag2item \"\$mtag\" $TTY_MENU_LIST )

Modified: head/usr.sbin/bsdconfig/mouse/mouse
==============================================================================
--- head/usr.sbin/bsdconfig/mouse/mouse	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/mouse/mouse	Sat Jun  1 23:58:44 2013	(r251236)
@@ -69,8 +69,8 @@ dialog_menu_main()
 	                        \"\$hline\"            \
 	                        $menu_list
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"          \
 		--backtitle \"\$DIALOG_BACKTITLE\"  \
 		--hline \"\$hline\"                 \
@@ -83,8 +83,9 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DEFAULTITEM_$$ "$dialog_menu"
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_data_sanitize menu_choice
+	f_dialog_menutag_store "$menu_choice"
+	setvar DEFAULTITEM_$$ "$menu_choice"
 	return $retval
 }
 
@@ -114,11 +115,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	"X $msg_exit") break ;;

Modified: head/usr.sbin/bsdconfig/mouse/port
==============================================================================
--- head/usr.sbin/bsdconfig/mouse/port	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/mouse/port	Sat Jun  1 23:58:44 2013	(r251236)
@@ -79,8 +79,8 @@ dialog_menu_main()
 	/dev/mse0)  defaultitem="6 $msg_busmouse" ;;
 	esac
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -93,7 +93,7 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -123,11 +123,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	"1 $msg_ps2") # PS/2 style mouse (/dev/psm0)

Modified: head/usr.sbin/bsdconfig/mouse/type
==============================================================================
--- head/usr.sbin/bsdconfig/mouse/type	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/mouse/type	Sat Jun  1 23:58:44 2013	(r251236)
@@ -87,8 +87,8 @@ dialog_menu_main()
 	thinkingmouse) defaultitem="A $msg_thinkingmouse" ;;
 	esac
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -101,7 +101,7 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -131,11 +131,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	"1 $msg_auto") # Bus mouse, PS/2 style mouse or PnP serial mouse

Modified: head/usr.sbin/bsdconfig/networking/devices
==============================================================================
--- head/usr.sbin/bsdconfig/networking/devices	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/networking/devices	Sat Jun  1 23:58:44 2013	(r251236)
@@ -73,13 +73,10 @@ f_mustberoot_init
 #
 defaultitem=""
 while :; do
-	f_dialog_menu_netdev "$defaultitem"
-	retval=$?
-	interface=$( f_dialog_menutag )
+	f_dialog_menu_netdev "$defaultitem" || break
+	f_dialog_menutag_fetch interface
 	defaultitem="$interface"
 
-	[ $retval -eq 0 ] || break
-
 	#
 	# dialog_menu_netdev adds an asterisk (*) to the right of the
 	# device name if the interface is active. Remove the asterisk

Modified: head/usr.sbin/bsdconfig/networking/networking
==============================================================================
--- head/usr.sbin/bsdconfig/networking/networking	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/networking/networking	Sat Jun  1 23:58:44 2013	(r251236)
@@ -67,8 +67,8 @@ dialog_menu_main()
 	                        \"\$hline\"            \
 	                        $menu_list
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"          \
 		--backtitle \"\$DIALOG_BACKTITLE\"  \
 		--hline \"\$hline\"                 \
@@ -81,8 +81,9 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DEFAULTITEM_$$ "$dialog_menu"
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_data_sanitize menu_choice
+	f_dialog_menutag_store "$menu_choice"
+	setvar DEFAULTITEM_$$ "$menu_choice"
 	return $retval
 }
 
@@ -112,11 +113,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	X) # Exit

Modified: head/usr.sbin/bsdconfig/networking/share/device.subr
==============================================================================
--- head/usr.sbin/bsdconfig/networking/share/device.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/networking/share/device.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -151,8 +151,8 @@ f_dialog_menu_netdev()
 	                        \"\$prompt\"           \
 	                        \"\$hline\"            \
 	                        $interfaces
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -165,7 +165,7 @@ f_dialog_menu_netdev()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -224,8 +224,8 @@ f_dialog_menu_netdev_edit()
 		                        \"\$prompt\"           \
 		                        \"\$hline\"            \
 		                        $menu_list
-		local dialog_menu
-		dialog_menu=$( eval $DIALOG \
+		local tag
+		tag=$( eval $DIALOG \
 			--title \"\$DIALOG_TITLE\"         \
 			--backtitle \"\$DIALOG_BACKTITLE\" \
 			--hline \"\$hline\"                \
@@ -240,10 +240,8 @@ f_dialog_menu_netdev_edit()
 			$menu_list                         \
 			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 		)
-
 		local retval=$?
-		setvar DIALOG_MENU_$$ "$dialog_menu"
-		local tag="$( f_dialog_menutag )"
+		f_dialog_data_sanitize tag
 
 		if [ $retval -eq 2 ]; then
 			# The Help button was pressed

Modified: head/usr.sbin/bsdconfig/networking/share/media.subr
==============================================================================
--- head/usr.sbin/bsdconfig/networking/share/media.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/networking/share/media.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -205,8 +205,8 @@ f_dialog_menu_media_options()
 
 	local hline="$hline_arrows_tab_enter"
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local tag
+	tag=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -216,11 +216,10 @@ f_dialog_menu_media_options()
 		$supported_media                   \
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
-
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_data_sanitize tag
+
 	if [ $retval -eq $SUCCESS ]; then
-		local tag="$( f_dialog_menutag )"
 		options=$( eval f_dialog_menutag2item \"\$tag\" \
 		                                      $supported_media )
 		[ "$options" = "$opt_none" ] && options=

Modified: head/usr.sbin/bsdconfig/networking/share/resolv.subr
==============================================================================
--- head/usr.sbin/bsdconfig/networking/share/resolv.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/networking/share/resolv.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -435,8 +435,8 @@ f_dialog_menu_nameservers()
 		                        \"\$prompt\"           \
 		                        \"\$hline\"            \
 		                        $menu_list
-		local dialog_menu
-		dialog_menu=$( eval $DIALOG \
+		local tag
+		tag=$( eval $DIALOG \
 			--title \"\$DIALOG_TITLE\"         \
 			--backtitle \"\$DIALOG_BACKTITLE\" \
 			--hline \"\$hline\"                \
@@ -448,10 +448,8 @@ f_dialog_menu_nameservers()
 			$menu_list                         \
 			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 		)
-
 		local retval=$?
-		setvar DIALOG_MENU_$$ "$dialog_menu"
-		local tag="$( f_dialog_menutag )" ns=""
+		f_dialog_data_sanitize tag
 
 		# Return if "Cancel" was chosen (-1) or ESC was pressed (255)
 		if [ $retval -ne $SUCCESS ]; then
@@ -467,6 +465,7 @@ f_dialog_menu_nameservers()
 			f_dialog_input_nameserver
 			;;
 		*)
+			local n ns
 			n=$( eval f_dialog_menutag2index \"\$tag\" $menu_list )
 			ns=$( eval f_dialog_menutag2item \"\$tag\" $menu_list )
 			f_dialog_input_nameserver $(( $n - 2 )) "$ns"

Modified: head/usr.sbin/bsdconfig/security/kern_securelevel
==============================================================================
--- head/usr.sbin/bsdconfig/security/kern_securelevel	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/security/kern_securelevel	Sat Jun  1 23:58:44 2013	(r251236)
@@ -81,8 +81,8 @@ dialog_menu_main()
 		defaultitem="$msg_disabled"
 	esac
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -98,7 +98,7 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -130,7 +130,7 @@ f_mustberoot_init
 while :; do
 	dialog_menu_main
 	retval=$?
-	mtag=$( f_dialog_menutag )
+	f_dialog_menutag_fetch mtag
 
 	if [ $retval -eq 2 ]; then
 		# The Help button was pressed

Modified: head/usr.sbin/bsdconfig/security/security
==============================================================================
--- head/usr.sbin/bsdconfig/security/security	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/security/security	Sat Jun  1 23:58:44 2013	(r251236)
@@ -105,8 +105,8 @@ dialog_menu_main()
 	                        \"\$hline\"            \
 	                        $menu_list
 
-	local dialog_menu
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -119,10 +119,11 @@ dialog_menu_main()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_data_sanitize menu_choice
+	f_dialog_menutag_store "$menu_choice"
 
 	# Only update default-item on success
-	[ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$dialog_menu"
+	[ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$menu_choice"
 
 	return $retval
 }
@@ -153,11 +154,8 @@ f_mustberoot_init
 # Launch application main menu
 #
 while :; do
-	dialog_menu_main
-	retval=$?
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || f_die
+	dialog_menu_main || f_die
+	f_dialog_menutag_fetch mtag
 
 	case "$mtag" in
 	"X <<< $msg_exit") break ;;

Modified: head/usr.sbin/bsdconfig/share/device.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/device.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/share/device.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -619,6 +619,7 @@ f_device_menu()
 	case $- in *e*) errexit=1; esac
 	set +e
 
+	local mtag
 	while :; do
 		mtag=$( eval $DIALOG \
 			--title \"\$title\"             \
@@ -648,8 +649,7 @@ f_device_menu()
 
 	if [ $retval -eq 0 ]; then
 		# Clean up the output of [X]dialog(1) and return it
-		setvar DIALOG_MENU_$$ "$mtag"
-		mtag=$( f_dialog_menutag )
+		f_dialog_data_sanitize mtag
 		echo "$mtag" >&2
 	fi
 

Modified: head/usr.sbin/bsdconfig/share/dialog.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/dialog.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/share/dialog.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -107,6 +107,45 @@ DIALOG_TIMEBOX_HEIGHT=6
 
 ############################################################ GENERIC FUNCTIONS
 
+# f_dialog_data_sanitize $var_to_edit ...
+#
+# When using dialog(1) or Xdialog(1) sometimes unintended warnings or errors
+# are generated from underlying libraries. For example, if $LANG is set to an
+# invalid or unknown locale, the warnings from the Xdialog(1) libraries will
+# clutter the output. This function helps by providing a centralied function
+# that removes spurious warnings from the dialog(1) (or Xdialog(1)) response.
+#
+# Simply pass the name of one or more variables that need to be sanitized.
+# After execution, the variables will hold their newly-sanitized data.
+#
+f_dialog_data_sanitize()
+{
+	if [ "$#" -eq 0 ]; then
+		f_dprintf "%s: called with zero arguments" \
+		          f_dialog_response_sanitize
+		return $FAILURE
+	fi
+
+	local __var_to_edit
+	for __var_to_edit in $*; do
+		# Skip warnings and trim leading/trailing whitespace
+		setvar $__var_to_edit "$( f_getvar $__var_to_edit | awk '
+			BEGIN { data = 0 }
+			{
+				if ( ! data )
+				{
+					if ( $0 ~ /^$/ ) next
+					if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next
+					data = 1
+				}
+				print
+			}
+		' )"
+	done
+}
+
+############################################################ TITLE FUNCTIONS
+
 # f_dialog_title [$new_title]
 #
 # Set the title of future dialog(1) ($DIALOG_TITLE) or backtitle of Xdialog(1)
@@ -1622,29 +1661,41 @@ f_dialog_input()
 
 ############################################################ MENU FUNCTIONS
 
-# f_dialog_menutag
+# f_dialog_menutag_store [-s] $text
+#
+# Store some text from a dialog(1) menu to be retrieved later by
+# f_dialog_menutag_fetch(). If the first argument is `-s', the text is
+# sanitized before being stored.
+#
+f_dialog_menutag_store()
+{
+	local sanitize=
+	[ "$1" = "-s" ] && sanitize=1 && shift 1 # -s
+	local text="$1"
+
+	# Sanitize the menutag before storing it if desired
+	[ "$sanitize" ] && f_dialog_data_sanitize text
+
+	setvar DIALOG_MENU_$$ "$text"
+}
+
+# f_dialog_menutag_fetch [$var_to_set]
 #
 # Obtain the menutag chosen by the user from the most recently displayed
-# dialog(1) menu and clean up any temporary files/variables.
+# dialog(1) menu (previously stored with f_dialog_menutag_store() above). If
+# $var_to_set is NULL or missing, output is printed to stdout (which is less
+# recommended due to performance degradation; in a loop for example).
 #
-f_dialog_menutag()
+f_dialog_menutag_fetch()
 {
-	# Skip warnings
-	eval echo \"\$DIALOG_MENU_$$\" | awk '
-		BEGIN { found = 0 }
-		{
-			if ( found ) # ... just spew
-			{
-				print
-				next
-			}
-			if ( $0 ~ /^$/ ) next
-			if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next
-			found = 1
-			print
-		}
-	'
+	local __var_to_set="$1" __cp
+
+	debug= f_getvar DIALOG_MENU_$$ "${__var_to_set:-__cp}" # get the data
 	setvar DIALOG_MENU_$$ "" # scrub memory in case data was sensitive
+
+	# Return the data on standard-out if desired
+	[ "$__var_to_set" ] || echo "$__cp"
+
 	return $SUCCESS
 }
 

Modified: head/usr.sbin/bsdconfig/share/media/any.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/any.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/share/media/any.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -94,10 +94,9 @@ f_media_get_type()
 	                        \"\$hline\"  \
 	                        $menu_list
 
-	local dialog_menu
-
+	local mtag
 	while :; do
-		dialog_menu=$( eval $DIALOG \
+		mtag=$( eval $DIALOG \
 			--title \"\$title\"             \
 			--backtitle \"\$btitle\"        \
 			--hline \"\$hline\"             \
@@ -112,10 +111,7 @@ f_media_get_type()
 			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 		)
 		local retval=$?
-		setvar DIALOG_MENU_$$ "$dialog_menu"
-
-		local mtag
-		mtag=$( f_dialog_menutag )
+		f_dialog_data_sanitize mtag
 		f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
 
 		if [ $retval -eq 2 ]; then

Modified: head/usr.sbin/bsdconfig/share/media/ftp.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/ftp.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/share/media/ftp.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -237,8 +237,8 @@ f_dialog_menu_media_ftp()
 	                        \"\$hline\"  \
 	                        $menu_list
 
-	local dialog_menu retval mtag value
-	dialog_menu=$( eval $DIALOG \
+	local mtag
+	mtag=$( eval $DIALOG \
 		--title \"\$title\"             \
 		--backtitle \"\$btitle\"        \
 		--hline \"\$hline\"             \
@@ -248,16 +248,13 @@ f_dialog_menu_media_ftp()
 		$height $width $rows            \
 		$menu_list                      \
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
-	)
-	retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
-	mtag=$( f_dialog_menutag )
-
-	[ $retval -eq 0 ] || return $FAILURE
+	) || return $FAILURE
+	f_dialog_data_sanitize mtag
 
 	case "$mtag" in
 	URL) setvar $VAR_FTP_PATH "other" ;;
 	*)
+		local value
 		value=$( eval f_dialog_menutag2item \"\$mtag\" $menu_list )
 		setvar $VAR_FTP_PATH "ftp://$value"
 	esac

Modified: head/usr.sbin/bsdconfig/share/media/options.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/options.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/share/media/options.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -208,9 +208,8 @@ f_media_options_menu()
 		                                  \"\$hline\"  \
 		                                  $menu_list
 
-		local dialog_menu
-
-		dialog_menu=$( eval $DIALOG \
+		local mtag
+		mtag=$( eval $DIALOG \
 			--title \"\$title\"              \
 			--backtitle \"\$btitle\"         \
 			--hline \"\$hline\"              \
@@ -227,11 +226,8 @@ f_media_options_menu()
 			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 		)
 		local retval=$?
-		setvar DIALOG_MENU_$$ "$dialog_menu"
-		defaultitem="$dialog_menu"
-
-		local mtag
-		mtag=$( f_dialog_menutag )
+		f_dialog_data_sanitize mtag
+		defaultitem="$mtag"
 		f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
 
 		if [ $retval -eq 2 ]; then

Modified: head/usr.sbin/bsdconfig/share/media/tcpip.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/tcpip.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/share/media/tcpip.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -1399,8 +1399,7 @@ f_device_dialog_tcp()
 					2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 				)
 				local retval=$?
-				setvar DIALOG_MENU_$$ "$cp"
-				cp=$( f_dialog_menutag )
+				f_dialog_data_sanitize cp
 				f_dprintf "retval=%u mtag=[%s]" $retval "$cp"
 
 				if [ $retval -eq 2 ]; then

Modified: head/usr.sbin/bsdconfig/share/mustberoot.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/mustberoot.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/share/mustberoot.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -105,8 +105,8 @@ f_become_root_via_sudo()
 		                        \"\$hline\"            \
 		                        $menu_list
 
-		local dialog_menu mtag retval
-		dialog_menu=$( eval $DIALOG \
+		local mtag
+		mtag=$( eval $DIALOG \
 			--title \"\$DIALOG_TITLE\"         \
 			--backtitle \"\$DIALOG_BACKTITLE\" \
 			--hline \"\$hline\"                \
@@ -116,12 +116,8 @@ f_become_root_via_sudo()
 			$height $width $rows               \
 			$menu_list                         \
 			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
-		)
-		retval=$?
-		setvar DIALOG_MENU_$$ "$dialog_menu"
-		mtag=$( f_dialog_menutag )
-
-		[ $retval -eq 0 ] || f_die
+		) || f_die
+		f_dialog_data_sanitize mtag
 
 		case "$mtag" in
 		X) # Cancel/Exit

Modified: head/usr.sbin/bsdconfig/share/packages/packages.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/packages/packages.subr	Sat Jun  1 22:53:11 2013	(r251235)
+++ head/usr.sbin/bsdconfig/share/packages/packages.subr	Sat Jun  1 23:58:44 2013	(r251236)
@@ -272,8 +272,8 @@ f_package_calculate_rundeps()
 # Dislay the menu of package categories, complete with package counts for each
 # category, accents, and other miscellany. If $defaultitem is non-NULL and
 # matches one of the existing menu-items, it will be pre-highlighted in the
-# menu dialog (HINT: Use f_dialog_menutag() to populate a local variable that
-# is passed as $defaultitem to highlight the user's last selection by default).
+# menu dialog (HINT: Use f_dialog_menutag_fetch() to populate a local variable
+# that is passed as $defaultitem to highlight the user's last selection).
 #
 f_package_menu_categories()
 {
@@ -297,14 +297,15 @@ f_package_menu_categories()
 		$category_list
 	" # End-Quote
 
-	local height width rows dialog_menu
+	local height width rows
 	eval f_dialog_menu_with_help_size height width rows \
 	                                  \"\$DIALOG_TITLE\"     \
 	                                  \"\$DIALOG_BACKTITLE\" \
 	                                  \"\$prompt\"           \
 	                                  \"\$hline\"            \
 	                                  $menu_list
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 			--title \"\$DIALOG_TITLE\"         \
 			--backtitle \"\$DIALOG_BACKTITLE\" \
 			--hline \"\$hline\"                \
@@ -318,7 +319,7 @@ f_package_menu_categories()
 			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 		)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"
 	return $retval
 }
 
@@ -360,7 +361,7 @@ f_package_index_get_page()
 #
 # On success, if the user doesn't press ESC or choose Cancel, the environment
 # variable $DIALOG_MENUITEM_$$ will hold the item associated with the chosen
-# tag (accessible through f_dialog_menutag()).
+# tag (accessible through f_dialog_menutag_fetch()).
 #
 f_package_menu_select()
 {
@@ -464,8 +465,9 @@ f_package_menu_select()
 	f_dialog_infobox_size iheight iwidth \
 	         	"$DIALOG_TITLE" "$DIALOG_BACKTITLE" \
 	         	"$msg_processing_selection"
-	local dialog_menu item
-	dialog_menu=$( eval $DIALOG \
+
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -484,11 +486,13 @@ f_package_menu_select()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_data_sanitize menu_choice
+	f_dialog_menutag_store "$menu_choice"
 
 	if [ $retval -eq $SUCCESS ]; then
+		local item
 		item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \
-		             	\"\$dialog_menu\" $menu_list )
+		             	\"\$menu_choice\" $menu_list )
 		setvar DIALOG_MENUITEM_$$ "$item"
 	fi
 
@@ -501,11 +505,11 @@ f_package_menu_select()
 # with regard to "deselecting" an already installed package. Choices include
 # uninstall, re-install, or cancel (leave $package marked as installed).
 # Returns success if the user does not press ESC or choose Cnacel. Use the
-# f_dialog_menutag() function upon success to retrieve the user's choice.
+# f_dialog_menutag_fetch() function upon success to retrieve the user's choice.
 #
 f_package_menu_deselect()
 {
-	local package="$1" prompt menu_list dialog_menu
+	local package="$1" prompt menu_list
 	prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" )
 	local hline="$hline_alnum_arrows_punc_tab_enter"
 	menu_list="
@@ -521,8 +525,8 @@ f_package_menu_deselect()
 	                        \"\$prompt\"           \
 	                        \"\$hline\"            \
 	                        $menu_list
-
-	dialog_menu=$( eval $DIALOG \
+	local menu_choice
+	menu_choice=$( eval $DIALOG \
 		--title \"\$DIALOG_TITLE\"         \
 		--backtitle \"\$DIALOG_BACKTITLE\" \
 		--hline \"\$hline\"                \
@@ -534,7 +538,7 @@ f_package_menu_deselect()
 		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
 	)
 	local retval=$?
-	setvar DIALOG_MENU_$$ "$dialog_menu"
+	f_dialog_menutag_store -s "$menu_choice"

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306012358.r51NwiFI006489>