From 44392705fac485378e053936384e4a310469eb77 Mon Sep 17 00:00:00 2001 From: Devin Teske Date: Tue, 4 Jun 2013 03:47:21 +0000 Subject: [PATCH] Use f_shell_escape() instead of forking to awk. In this case, the replacement comes with a great performance increase (as f_shell_escape() uses the built-in based f_replaceall() which out-performs forking to awk(1)). This should also improve readability slightly. --- usr.sbin/bsdconfig/bsdconfig | 5 ++--- usr.sbin/bsdconfig/share/device.subr | 4 +--- usr.sbin/bsdconfig/share/variable.subr | 5 +++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/usr.sbin/bsdconfig/bsdconfig b/usr.sbin/bsdconfig/bsdconfig index cecedb3eb789..340beb80d2b8 100755 --- a/usr.sbin/bsdconfig/bsdconfig +++ b/usr.sbin/bsdconfig/bsdconfig @@ -167,7 +167,6 @@ dialog_menu_main() local defaultitem= # Calculated below local hline= - local sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }" local menuitem menu_title menu_help menu_selection index=2 for menuitem in $( cd $BSDCFG_LIBE && ls -d [0-9][0-9][0-9].* ); do [ $index -lt ${#DIALOG_MENU_TAGS} ] || break @@ -185,8 +184,8 @@ dialog_menu_main() menu_program="$menuitem/$menu_program" esac - menu_title=$( echo "$menu_title" | awk "$sanitize_awk" ) - menu_help=$( echo "$menu_help" | awk "$sanitize_awk" ) + f_shell_escape "$menu_title" menu_title + f_shell_escape "$menu_help" menu_help setvar "menu_program$tag" "$menu_program" menu_list="$menu_list '$tag' '$menu_title' '$menu_help'" diff --git a/usr.sbin/bsdconfig/share/device.subr b/usr.sbin/bsdconfig/share/device.subr index f724af47fd28..28e3ee8f914b 100644 --- a/usr.sbin/bsdconfig/share/device.subr +++ b/usr.sbin/bsdconfig/share/device.subr @@ -598,12 +598,10 @@ f_device_menu() done [ "$devs" ] || return $FAILURE - local sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }" - local desc menu_list= for dev in $devs; do device_$dev get desc desc - desc=$( echo "$desc" | awk "$sanitize_awk" ) + f_shell_escape "$desc" desc menu_list="$menu_list '$dev' '$desc'" done diff --git a/usr.sbin/bsdconfig/share/variable.subr b/usr.sbin/bsdconfig/share/variable.subr index 079c5643f379..879eece7ba32 100644 --- a/usr.sbin/bsdconfig/share/variable.subr +++ b/usr.sbin/bsdconfig/share/variable.subr @@ -32,6 +32,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 f_dprintf "%s: loading includes..." variable.subr f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/strings.subr ############################################################ GLOBALS @@ -130,12 +131,12 @@ f_variable_set_defaults() # f_dump_variables() { - local err sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }" + local err if ! err=$( ( for handle in $VARIABLES; do f_getvar $handle var || continue f_getvar $var value || continue - value=$( echo "$value" | awk "$sanitize_awk" ) + f_shell_escape "$value" value printf "%s='%s'\n" "$var" "$value" done > "$VARIABLE_DUMPFILE" ) 2>&1 ); then