diff options
author | dteske <dteske@FreeBSD.org> | 2013-06-02 05:45:25 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-06-02 05:45:25 +0000 |
commit | 5b05f067655217732e94ad77b1c57a3cb7a3945e (patch) | |
tree | c82ae86b5bfe7b5e527099673025931ffda2e584 /usr.sbin/bsdconfig/networking | |
parent | c13ee16ab4b2ed670be4b050ae59d428dab4196f (diff) | |
download | FreeBSD-src-5b05f067655217732e94ad77b1c57a3cb7a3945e.zip FreeBSD-src-5b05f067655217732e94ad77b1c57a3cb7a3945e.tar.gz |
Similar to r251236, improve the portion of dialog(1) API in dialog.subr
responsible for retrieving stored input (for the --inputbox and --password
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 a very long time, so the need to always execute some clean-up
function is long-deprecated. The function that used to perform these clean-
up routines for these widgets was f_dialog_inputstr().
We really don't need f_dialog_inputstr() for its originally designed purpose
as all dialog invocations no longer require temporary files.
Just as in r251236, redesign f_dialog_inputstr() in the following four ways:
1. Rename f_dialog_inputstr() to f_dialog_inputstr_fetch()
2. Introduce the new first-argument of $var_to_set to reduce forking
3. Create a corresponding f_dialog_inputstr_store() to abstract storage
4. Offload the sanitization to a new function, f_dialog_line_sanitize()
It should be noted that f_dialog_line_sanitize() -- unlike its cousin from
SVN r251236, f_dialog_data_sanitize() -- trims leading/trailing whitespace
from the user's input. This helps prevent errors and common mistakes caused
by the fact that the new cdialog implementation allows the right-arrow
cursor key to go beyond the last byte of realtime input (adding whitespace
at the end of the typed value).
While we're centralizing the sanitization, let's rewrite f_dialog_input()
while we're here to likewise reduce forking. The f_dialog_input() function
now expects the first argument of $var_to_set instead of producing results
on standard-out.
These changes greatly improve readability and also improve performance.
Diffstat (limited to 'usr.sbin/bsdconfig/networking')
6 files changed, 14 insertions, 21 deletions
diff --git a/usr.sbin/bsdconfig/networking/share/hostname.subr b/usr.sbin/bsdconfig/networking/share/hostname.subr index 61df2b4..5fc3f5a 100644 --- a/usr.sbin/bsdconfig/networking/share/hostname.subr +++ b/usr.sbin/bsdconfig/networking/share/hostname.subr @@ -108,9 +108,8 @@ f_dialog_input_hostname() # Loop until the user provides taint-free input. # while :; do - hostname=$( f_dialog_input "$msg" "$hostname" \ - "$hline_alnum_punc_tab_enter" - ) || return + f_dialog_input hostname "$msg" "$hostname" \ + "$hline_alnum_punc_tab_enter" || return # Taint-check the user's input f_dialog_validate_hostname "$hostname" && break done diff --git a/usr.sbin/bsdconfig/networking/share/ipaddr.subr b/usr.sbin/bsdconfig/networking/share/ipaddr.subr index 4b39dd2..69777b2 100644 --- a/usr.sbin/bsdconfig/networking/share/ipaddr.subr +++ b/usr.sbin/bsdconfig/networking/share/ipaddr.subr @@ -162,9 +162,8 @@ f_dialog_input_ipaddr() # - User has either pressed ESC or chosen Cancel/No # - User has not made any changes to the given value # - _input=$( f_dialog_input "$msg" "$_ipaddr" \ - "$hline_num_punc_tab_enter" - ) || return + f_dialog_input _input "$msg" "$_ipaddr" \ + "$hline_num_punc_tab_enter" || return [ "$_ipaddr" = "$_input" ] && return $FAILURE # Return success if NULL value was entered diff --git a/usr.sbin/bsdconfig/networking/share/media.subr b/usr.sbin/bsdconfig/networking/share/media.subr index 0ed7637..3c7f473 100644 --- a/usr.sbin/bsdconfig/networking/share/media.subr +++ b/usr.sbin/bsdconfig/networking/share/media.subr @@ -122,8 +122,8 @@ f_dialog_input_options() local msg="$( printf "$msg_please_enter_mediaopts" "$interface" )" local hline="$hline_alnum_punc_tab_enter" - local dialog_inputbox - dialog_inputbox=$( $DIALOG \ + local _options + _options=$( $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --hline "$hline" \ @@ -133,10 +133,8 @@ f_dialog_input_options() "$options" \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) - local retval=$? - setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" - local _options="$( f_dialog_inputstr )" + f_dialog_line_sanitize _options [ $retval -eq $SUCCESS ] && options="$_options" diff --git a/usr.sbin/bsdconfig/networking/share/netmask.subr b/usr.sbin/bsdconfig/networking/share/netmask.subr index e6838e5..079b21d 100644 --- a/usr.sbin/bsdconfig/networking/share/netmask.subr +++ b/usr.sbin/bsdconfig/networking/share/netmask.subr @@ -110,9 +110,8 @@ f_dialog_input_netmask() # - User has either pressed ESC or chosen Cancel/No # - User has not made any changes to the given value # - _input=$( f_dialog_input "$msg" "$_netmask" \ - "$hline_num_punc_tab_enter" - ) || return + f_dialog_input _input "$msg" "$_netmask" \ + "$hline_num_punc_tab_enter" || return [ "$_netmask" = "$_input" ] && return $FAILURE # Return success if NULL value was entered diff --git a/usr.sbin/bsdconfig/networking/share/resolv.subr b/usr.sbin/bsdconfig/networking/share/resolv.subr index 0793c81..59e0332 100644 --- a/usr.sbin/bsdconfig/networking/share/resolv.subr +++ b/usr.sbin/bsdconfig/networking/share/resolv.subr @@ -311,9 +311,8 @@ f_dialog_input_nameserver() # Loop until the user provides taint-free input. # while :; do - new_ns=$( f_dialog_input "$msg" "$ns" \ - "$hline_num_punc_tab_enter" - ) || return + f_dialog_input new_ns "$msg" "$ns" \ + "$hline_num_punc_tab_enter" || return # Take only the first "word" of the user's input new_ns="${new_ns%%[$IFS]*}" diff --git a/usr.sbin/bsdconfig/networking/share/routing.subr b/usr.sbin/bsdconfig/networking/share/routing.subr index 2d8cafc..32c53f5 100644 --- a/usr.sbin/bsdconfig/networking/share/routing.subr +++ b/usr.sbin/bsdconfig/networking/share/routing.subr @@ -83,10 +83,9 @@ f_dialog_input_defaultrouter() # local retval while :; do - defaultrouter=$( f_dialog_input \ - "$msg_please_enter_default_router" \ - "$defaultrouter" "$hline_num_punc_tab_enter" - ) + f_dialog_input defaultrouter \ + "$msg_please_enter_default_router" \ + "$defaultrouter" "$hline_num_punc_tab_enter" retval=$? [ "$defaultrouter" ] || return $SUCCESS [ $retval -eq $SUCCESS ] || return $retval |