summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/timezone
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2013-12-07 00:31:01 +0000
committerdteske <dteske@FreeBSD.org>2013-12-07 00:31:01 +0000
commitea67b8239d4b9fc5ec66acb0b55c08b6724c220c (patch)
tree2bf3a34e8912087de92cb6b8e1a3cdfe286c7877 /usr.sbin/bsdconfig/timezone
parent553f713863e06db13e30699129b501901c7ad3de (diff)
downloadFreeBSD-src-ea67b8239d4b9fc5ec66acb0b55c08b6724c220c.zip
FreeBSD-src-ea67b8239d4b9fc5ec66acb0b55c08b6724c220c.tar.gz
Performance and debugging enhancements:
+ Remove UNAME_P=$(...) from startup/misc -- already supplied by common.subr + Use f_getvar instead of $(eval echo \$$var) -- f_getvar is sub-shell free + Add `-e' and `-k var' options to f_eval_catch -- increasing use-cases + Use f_eval_catch to display errors on failure -- reducing duplicated code + Use f_eval_catch when we need output from a command -- improving debugging + Optimize f_isinter of strings.subr for performance -- now sub-shell free + Improve error checking on pidfiles -- using f_eval_catch and f_isinteger + Use $var_to_set arg of f_ifconfig_{inet,netmask} -- eliminate sub-shells + Use f_sprintf instead of $(printf ...) -- consolidate sub-shells + Use $var_to_set arg of f_route_get_default -- eliminate sub-shells + Add f_count to replace $(set -- ...;echo $#) -- eliminate sub-shells + Add f_count_ifs to replace $(IFS=x;set -- ...;echo $#) -- no sub-shells + Replace var="$var${var:+ }..." in loops with var="$var ..." with a follow- up var="${var# }" to trim leading whitespace -- optimize loops + Use $var_to_set arg of f_resolv_conf_nameservers -- eliminate sub-shells + Comments for the f_eval_catch function + Remove a duplicate `local ... desc ...' in f_device_get_all of device.subr + Use $var_to_set arg of f_device_capacity -- eliminate sub-shells + Whitespace fixes in f_dialog_init of dialog.subr + Optimize f_inet_atoi of media/tcpip.subr for performance -- sub-shell free + In several cases, send stderr to /dev/null -- clean up runtime execution + Change f_err of common.subr to go to program stderr not terminal stderr, allowing redirection of output from functions that use f_err + Disable debugging when using f_getvar to get variable argument to f_startup_rcconf_map_expand of startup/rcconf.subr + Use f_replace_all instead of $(echo ... | tr | sed) -- performance + Add a $var_to_set option to f_index_{file,menusel_{command,keyword}} of common.subr -- centralize sub-shells
Diffstat (limited to 'usr.sbin/bsdconfig/timezone')
-rw-r--r--usr.sbin/bsdconfig/timezone/share/zones.subr156
-rwxr-xr-xusr.sbin/bsdconfig/timezone/timezone23
2 files changed, 52 insertions, 127 deletions
diff --git a/usr.sbin/bsdconfig/timezone/share/zones.subr b/usr.sbin/bsdconfig/timezone/share/zones.subr
index b356323..59a9330 100644
--- a/usr.sbin/bsdconfig/timezone/share/zones.subr
+++ b/usr.sbin/bsdconfig/timezone/share/zones.subr
@@ -32,6 +32,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." timezone/zones.subr
f_include $BSDCFG_SHARE/dialog.subr
+f_include $BSDCFG_SHARE/strings.subr
f_include $BSDCFG_SHARE/timezone/continents.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="090.timezone"
@@ -347,8 +348,9 @@ f_read_zones()
#
f_install_zoneinfo_file()
{
+ local funcname=f_install_zoneinfo_file
local zoneinfo_file="$1"
- local copymode title msg err height width
+ local copymode title msg height width
if [ -L "$_PATH_LOCALTIME" ]; then
copymode=
@@ -361,13 +363,13 @@ f_install_zoneinfo_file()
if [ "$VERBOSE" ]; then
if [ ! "$zoneinfo_file" ]; then
- msg=$( printf "$msg_removing_file" "$_PATH_LOCALTIME" )
+ f_sprintf msg "$msg_removing_file" "$_PATH_LOCALTIME"
elif [ "$copymode" ]; then
- msg=$( printf "$msg_copying_file" \
- "$zoneinfo_file" "$_PATH_LOCALTIME" )
+ f_sprintf msg "$msg_copying_file" \
+ "$zoneinfo_file" "$_PATH_LOCALTIME"
else
- msg=$( printf "$msg_creating_symlink" \
- "$_PATH_LOCALTIME" "$zoneinfo_file" )
+ f_sprintf msg "$msg_creating_symlink" \
+ "$_PATH_LOCALTIME" "$zoneinfo_file"
fi
if [ "$USEDIALOG" ]; then
f_dialog_title "$msg_info"
@@ -380,33 +382,17 @@ f_install_zoneinfo_file()
[ "$REALLYDOIT" ] || return $SUCCESS
- if [ ! "$zoneinfo_file" ]; then
- err=$( rm -f "$_PATH_LOCALTIME" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- f_dialog_title "$msg_error"
- f_dialog_msgbox "$err"
- f_dialog_title_restore
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
- fi
+ local catch_args="-de"
+ [ "$USEDIALOG" ] && catch_args=
- err=$( rm -f "$_PATH_DB" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- f_dialog_title "$msg_error"
- f_dialog_msgbox "$err"
- f_dialog_title_restore
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
- fi
+ if [ ! "$zoneinfo_file" ]; then
+ f_eval_catch $catch_args $funcname rm \
+ 'rm -f "%s"' "$_PATH_LOCALTIME" || return $FAILURE
+ f_eval_catch $catch_args $funcname rm \
+ 'rm -f "%s"' "$_PATH_DB" || return $FAILURE
if [ "$VERBOSE" ]; then
- msg=$( printf "$msg_removed_file" "$_PATH_LOCALTIME" )
+ f_sprintf msg "$msg_removed_file" "$_PATH_LOCALTIME"
if [ "$USEDIALOG" ]; then
f_dialog_title "$msg_done"
f_dialog_msgbox "$msg"
@@ -415,96 +401,35 @@ f_install_zoneinfo_file()
printf "%s\n" "$msg"
fi
fi
-
return $SUCCESS
-
fi # ! zoneinfo_file
if [ "$copymode" ]; then
-
- err=$( rm -f "$_PATH_LOCALTIME" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- f_dialog_title "$msg_error"
- f_dialog_msgbox "$err"
- f_dialog_title_restore
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
- fi
-
- err=$( umask 222 && : 2>&1 > "$_PATH_LOCALTIME" )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- f_dialog_title "$msg_error"
- f_dialog_msgbox "$err"
- f_dialog_title_restore
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
- fi
-
- err=$( cat "$zoneinfo_file" 2>&1 > "$_PATH_LOCALTIME" )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- f_dialog_title "$msg_error"
- f_dialog_msgbox "$err"
- f_dialog_title_restore
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
- fi
-
- else # ! copymode
-
- err=$( ( :< "$zoneinfo_file" ) 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- f_dialog_title "$msg_error"
- f_dialog_msgbox "$err"
- f_dialog_title_restore
- else
- f_err "%s\n" "$err"
- fi
+ f_eval_catch $catch_args $funcname rm \
+ 'rm -f "%s"' "$_PATH_LOCALTIME" || return $FAILURE
+ f_eval_catch $catch_args $funcname sh \
+ 'umask 222 && :> "%s"' "$_PATH_LOCALTIME" ||
return $FAILURE
- fi
-
- err=$( rm -f "$_PATH_LOCALTIME" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- f_dialog_title "$msg_error"
- f_dialog_msgbox "$err"
- f_dialog_title_restore
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
- fi
-
- err=$( ln -s "$zoneinfo_file" "$_PATH_LOCALTIME" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- f_dialog_title "$msg_error"
- f_dialog_msgbox "$err"
- f_dialog_title_restore
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
- fi
-
+ f_eval_catch $catch_args $funcname sh \
+ 'cat "%s" > "%s"' \
+ "$zoneinfo_file" "$_PATH_LOCALTIME" || return $FAILURE
+ else
+ f_eval_catch $catch_args $funcname sh \
+ '( :< "%s" )' "$zoneinfo_file" || return $FAILURE
+ f_eval_catch $catch_args $funcname rm \
+ 'rm -f "%s"' "$_PATH_LOCALTIME" || return $FAILURE
+ f_eval_catch $catch_args $funcname ln \
+ 'ln -s "%s" "%s"' \
+ "$zoneinfo_file" "$_PATH_LOCALTIME" || return $FAILURE
fi # copymode
if [ "$VERBOSE" ]; then
if [ "$copymode" ]; then
- msg=$( printf "$msg_copied_timezone_file" \
- "$zoneinfo_file" "$_PATH_LOCALTIME" )
+ f_sprintf msg "$msg_copied_timezone_file" \
+ "$zoneinfo_file" "$_PATH_LOCALTIME"
else
- msg=$( printf "$msg_created_symlink" \
- "$_PATH_LOCALTIME" "$zoneinfo_file" )
+ f_sprintf msg "$msg_created_symlink" \
+ "$_PATH_LOCALTIME" "$zoneinfo_file"
fi
if [ "$USEDIALOG" ]; then
f_dialog_title "$msg_done"
@@ -559,16 +484,17 @@ f_confirm_zone()
local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
f_dialog_title_restore
local tm_zone="$( TZ="$filename" date +%Z )"
- local prompt="$( printf "$msg_look_reasonable" "$tm_zone" )"
+ local prompt # Calculated below
local height=5 width=72
+ f_sprintf prompt "$msg_look_reasonable" "$tm_zone"
if [ "$USE_XDIALOG" ]; then
height=$(( $height + 4 ))
$DIALOG \
- --title "$title" \
- --backtitle "$btitle" \
- --ok-label "$msg_yes" \
- --cancel-label "$msg_no" \
+ --title "$title" \
+ --backtitle "$btitle" \
+ --ok-label "$msg_yes" \
+ --cancel-label "$msg_no" \
--yesno "$prompt" $height $width
else
$DIALOG \
diff --git a/usr.sbin/bsdconfig/timezone/timezone b/usr.sbin/bsdconfig/timezone/timezone
index d4b7ab5..0452230 100755
--- a/usr.sbin/bsdconfig/timezone/timezone
+++ b/usr.sbin/bsdconfig/timezone/timezone
@@ -43,8 +43,8 @@ f_include $BSDCFG_SHARE/timezone/zones.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="090.timezone"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
-ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
-[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
+f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
+ pgm="${ipgm:-$pgm}"
############################################################ CONFIGURATION
@@ -164,7 +164,7 @@ fi
if [ "$REINSTALL" ]; then
[ -f "$_PATH_DB" -a -r "$_PATH_DB" ] ||
f_die 1 "$msg_cannot_open_for_reading" "$_PATH_DB"
- zoneinfo=$( cat "$_PATH_DB" ) ||
+ f_eval_catch -dk zoneinfo "$0" cat 'cat "%s"' "$_PATH_DB" ||
f_die 1 "$msg_error_reading" "$_PATH_DB"
[ "$zoneinfo" ] ||
f_die 1 "$msg_unable_to_determine_name_from_db" "$_PATH_DB"
@@ -244,7 +244,7 @@ if [ $# -ge 1 ]; then
default="$1"
f_dialog_title "$msg_default_zone_provided"
- msg=$( printf "\n$msg_use_default_zone" "$default" )
+ f_sprintf msg "\n$msg_use_default_zone" "$default"
hline=
f_dialog_yesno "$msg" "$hline"
result=$?
@@ -322,16 +322,16 @@ while :; do
# It's amazing how much good grammar really matters...
#
if [ ! "$isocean" ]; then
- title=$( printf "$msg_country_title" \
- "$cont_title" )
+ f_sprintf title "$msg_country_title" \
+ "$cont_title"
f_dialog_title "$title"
title="$DIALOG_TITLE"
btitle="$DIALOG_BACKTITLE"
f_dialog_title_restore
prompt="$msg_select_country"
else
- title=$( printf "$msg_island_and_group_title" \
- "$cont_title" )
+ f_sprintf title "$msg_island_and_group_title" \
+ "$cont_title"
f_dialog_title "$title"
title="$DIALOG_TITLE"
btitle="$DIALOG_BACKTITLE"
@@ -397,11 +397,10 @@ while :; do
continue
fi
else
- title=$( printf "$msg_country_time_zones" \
- "$( f_country $tlc name )" )
+ f_sprintf title "$msg_country_time_zones" \
+ "$( f_country $tlc name )"
f_dialog_title "$title"
- title="$DIALOG_TITLE"
- btitle="$DIALOG_BACKTITLE"
+ title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
f_dialog_title_restore
prompt="$msg_select_zone"
menu_list=$( f_country $tlc menu_list )
OpenPOWER on IntegriCloud