diff options
author | dteske <dteske@FreeBSD.org> | 2013-06-01 23:58:44 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-06-01 23:58:44 +0000 |
commit | 9e2431c34dc087e0ff7bb1a5ae076865b37fd54e (patch) | |
tree | aff553824a76a9a13ba24f03ece60b3c50def184 /usr.sbin/bsdconfig/security | |
parent | 2201176ef968245558d98feec1de87cfdca36bf4 (diff) | |
download | FreeBSD-src-9e2431c34dc087e0ff7bb1a5ae076865b37fd54e.zip FreeBSD-src-9e2431c34dc087e0ff7bb1a5ae076865b37fd54e.tar.gz |
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.
Diffstat (limited to 'usr.sbin/bsdconfig/security')
-rwxr-xr-x | usr.sbin/bsdconfig/security/kern_securelevel | 8 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/security/security | 16 |
2 files changed, 11 insertions, 13 deletions
diff --git a/usr.sbin/bsdconfig/security/kern_securelevel b/usr.sbin/bsdconfig/security/kern_securelevel index 6681da8..69c28b2 100755 --- a/usr.sbin/bsdconfig/security/kern_securelevel +++ b/usr.sbin/bsdconfig/security/kern_securelevel @@ -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 diff --git a/usr.sbin/bsdconfig/security/security b/usr.sbin/bsdconfig/security/security index 1000e45..eb7a73d 100755 --- a/usr.sbin/bsdconfig/security/security +++ b/usr.sbin/bsdconfig/security/security @@ -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 ;; |