diff options
author | dteske <dteske@FreeBSD.org> | 2014-01-15 07:49:17 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2014-01-15 07:49:17 +0000 |
commit | a35804263ce5ac47cb5d4819f6b5c9933997c9b0 (patch) | |
tree | 5307c06d0753e37d7f6c7040f0ae9896e2701ecd /usr.sbin/bsdconfig/usermgmt | |
parent | 44abef95373cf49911f4c9bf27ad329cccbd3a05 (diff) | |
download | FreeBSD-src-a35804263ce5ac47cb5d4819f6b5c9933997c9b0.zip FreeBSD-src-a35804263ce5ac47cb5d4819f6b5c9933997c9b0.tar.gz |
MFC r259054:
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/usermgmt')
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/groupadd | 4 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/groupdel | 4 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/groupedit | 4 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/groupinput | 46 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/usermgmt/share/group_input.subr | 9 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/usermgmt/share/user_input.subr | 8 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/useradd | 4 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/userdel | 4 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/useredit | 4 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/userinput | 93 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/usermgmt | 4 |
11 files changed, 74 insertions, 110 deletions
diff --git a/usr.sbin/bsdconfig/usermgmt/groupadd b/usr.sbin/bsdconfig/usermgmt/groupadd index 6f806a6..62f062d 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupadd +++ b/usr.sbin/bsdconfig/usermgmt/groupadd @@ -36,8 +36,8 @@ f_include $BSDCFG_SHARE/dialog.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" -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}" ############################################################ MAIN diff --git a/usr.sbin/bsdconfig/usermgmt/groupdel b/usr.sbin/bsdconfig/usermgmt/groupdel index 2f41164..aa1c305 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupdel +++ b/usr.sbin/bsdconfig/usermgmt/groupdel @@ -39,8 +39,8 @@ f_include $BSDCFG_SHARE/usermgmt/group_input.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" 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}" ############################################################ MAIN diff --git a/usr.sbin/bsdconfig/usermgmt/groupedit b/usr.sbin/bsdconfig/usermgmt/groupedit index 3eacaff..953f4f5 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupedit +++ b/usr.sbin/bsdconfig/usermgmt/groupedit @@ -39,8 +39,8 @@ f_include $BSDCFG_SHARE/usermgmt/group_input.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" 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}" ############################################################ MAIN diff --git a/usr.sbin/bsdconfig/usermgmt/groupinput b/usr.sbin/bsdconfig/usermgmt/groupinput index 5b60bb2..f98e890 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupinput +++ b/usr.sbin/bsdconfig/usermgmt/groupinput @@ -39,8 +39,8 @@ f_include $BSDCFG_SHARE/usermgmt/group_input.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" 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 @@ -56,16 +56,12 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # save_changes() { - local err retval=$SUCCESS + local funcname=save_changes case "$mode" in Delete) - err=$( pw groupdel "$group_name" 2>&1 ) - retval=$? - if [ $retval -ne $SUCCESS ]; then - f_dialog_msgbox "$msg_error $err\n" - return $retval - fi + f_eval_catch $funcname pw 'pw groupdel "%s"' "$group_name" || + return $? f_show_msg "$msg_group_deleted" ;; Add) @@ -74,17 +70,13 @@ save_changes() [ "$group_members" != "$cur_group_members" ] && cmd="$cmd -M '$group_members'" if [ "$pw_group_password_disable" ]; then - cmd="$cmd -h -" + f_eval_catch $funcname pw '%s -h -' "$cmd" elif [ "$group_password" ]; then - cmd="echo \"\$group_password\" | $cmd -h 0" - fi - f_dprintf "cmd=%s" "$cmd" - err=$( eval $cmd 2>&1 ) - retval=$? - if [ $retval -ne $SUCCESS ]; then - f_dialog_msgbox "$msg_error $err\n" - return $retval - fi + echo "$group_password" | + f_eval_catch $funcname pw '%s -h 0' "$cmd" + else + f_eval_catch $funcname pw '%s' "$cmd" + fi || return $? f_show_msg "$msg_group_added" ;; Edit/View) @@ -93,17 +85,13 @@ save_changes() [ "$group_members" != "$cur_group_members" ] && cmd="$cmd -M '$group_members'" if [ "$pw_group_password_disable" ]; then - cmd="$cmd -h -" + f_eval_catch $funcname pw '%s -h -' "$cmd" elif [ "$group_password" ]; then - cmd="echo \"\$group_password\" | $cmd -h 0" - fi - f_dprintf "cmd=%s" "$cmd" - err=$( eval $cmd 2>&1 ) - retval=$? - if [ $retval -ne $SUCCESS ]; then - f_dialog_msgbox "$msg_error $err\n" - return $retval - fi + echo "$group_password" | + f_eval_catch $funcname pw '%s -h 0' "$cmd" + else + f_eval_catch $funcname pw '%s' "$cmd" + fi || return $? f_show_msg "$msg_group_updated" ;; esac diff --git a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr index 2ca141e..e0f47f7 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr @@ -371,15 +371,12 @@ f_dialog_input_group_members() # pressed ESC or chose Cancel/No f_dialog_data_sanitize _group_members + # # Convert the newline separated list into a comma- # separated one so that if the user switches over to # manual editing, list reflects checklist selections - _group_members=$( echo "$_group_members" | - tr '\n' ' ' | - sed -e 's/[[:space:]]\{1,\}/,/g;s/^,//;s/,$//' - ) - - _input="$_group_members" + # + f_replaceall "$_group_members" "[$IFS]" "," _input ;; 2) # Enter Group Members manually local p="$msg_group_members ($msg_separated_by_commas)" diff --git a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr index bd2fc9b..c95685c 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr @@ -599,8 +599,8 @@ f_dialog_input_expire_password() 4) # Enter value manually local msg ret_secs - msg=$( printf "$msg_number_of_seconds_since_epoch" \ - "$( date -r 1 "+%c %Z" )" ) + f_sprintf msg "$msg_number_of_seconds_since_epoch" \ + "$( date -r 1 "+%c %Z" )" # Return to menu if either ESC or Cancel/No f_dialog_input ret_secs \ @@ -783,8 +783,8 @@ f_dialog_input_expire_account() 4) # Enter value manually local msg ret_secs - msg=$( printf "$msg_number_of_seconds_since_epoch" \ - "$( date -r 1 "+%c %Z" )" ) + f_sprintf msg "$msg_number_of_seconds_since_epoch" \ + "$( date -r 1 "+%c %Z" )" # Return to menu if either ESC or Cancel/No f_dialog_input ret_secs "$msg" \ diff --git a/usr.sbin/bsdconfig/usermgmt/useradd b/usr.sbin/bsdconfig/usermgmt/useradd index b8cac27..2d6b4d0 100755 --- a/usr.sbin/bsdconfig/usermgmt/useradd +++ b/usr.sbin/bsdconfig/usermgmt/useradd @@ -36,8 +36,8 @@ f_include $BSDCFG_SHARE/dialog.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" -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}" ############################################################ MAIN diff --git a/usr.sbin/bsdconfig/usermgmt/userdel b/usr.sbin/bsdconfig/usermgmt/userdel index 299e25b..33aa062 100755 --- a/usr.sbin/bsdconfig/usermgmt/userdel +++ b/usr.sbin/bsdconfig/usermgmt/userdel @@ -39,8 +39,8 @@ f_include $BSDCFG_SHARE/usermgmt/user_input.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" 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}" ############################################################ MAIN diff --git a/usr.sbin/bsdconfig/usermgmt/useredit b/usr.sbin/bsdconfig/usermgmt/useredit index a4bee68..30ee578 100755 --- a/usr.sbin/bsdconfig/usermgmt/useredit +++ b/usr.sbin/bsdconfig/usermgmt/useredit @@ -39,8 +39,8 @@ f_include $BSDCFG_SHARE/usermgmt/user_input.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" 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}" ############################################################ MAIN diff --git a/usr.sbin/bsdconfig/usermgmt/userinput b/usr.sbin/bsdconfig/usermgmt/userinput index aad6ef3..5cf5554 100755 --- a/usr.sbin/bsdconfig/usermgmt/userinput +++ b/usr.sbin/bsdconfig/usermgmt/userinput @@ -39,8 +39,8 @@ f_include $BSDCFG_SHARE/usermgmt/user_input.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" 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 @@ -74,29 +74,24 @@ copy_dotfiles() # save_changes() { - local err retval=$SUCCESS + local funcname=save_changes case "$mode" in Delete) - err=$( pw userdel -u "$pw_uid" 2>&1 ) - retval=$? - if [ $retval -ne $SUCCESS ]; then - f_dialog_msgbox "$msg_error $err\n" - return $retval - fi + f_eval_catch $funcname pw 'pw userdel -u "%s"' "$pw_uid" || + return $? f_show_msg "$msg_login_deleted" if [ "$pw_group_delete" = "$msg_yes" ] && f_quietly pw groupshow -g "$pw_gid" then - err=$( pw groupdel -g "$pw_gid" 2>&1 ) || - f_dialog_msgbox "$msg_warning $err\n" + f_eval_catch $funcname pw \ + 'pw groupdel -g "%s"' "$pw_gid" fi if [ "$pw_home_delete" = "$msg_yes" ]; then f_dialog_info "$msg_deleting_home_directory" - err=$( rm -Rf "$pw_home_dir" 2>&1 ) || - f_dialog_msgbox "$msg_warning $err\n" + f_eval_catch $funcname rm 'rm -Rf "%s"' "$pw_home_dir" fi ;; Add) @@ -111,35 +106,27 @@ save_changes() [ "$pw_shell" ] && cmd="$cmd -s '$pw_shell'" [ "$pw_uid" ] && cmd="$cmd -u '$pw_uid'" if [ "$pw_password_disable" ]; then - cmd="$cmd -h -" + f_eval_catch $funcname pw '%s -h -' "$cmd" elif [ "$pw_password" ]; then - cmd="echo \"\$pw_password\" | $cmd -h 0" - fi - f_dprintf "cmd=%s" "$cmd" - err=$( eval $cmd 2>&1 ) - retval=$? - if [ $retval -ne $SUCCESS ]; then - f_dialog_msgbox "$msg_error $err\n" - return $retval - fi + echo "$pw_password" | + f_eval_catch $funcname pw '%s -h 0' "$cmd" + else + f_eval_catch $funcname pw '%s' "$cmd" + fi || return $? f_show_msg "$msg_login_added" if [ "$pw_home_create" = "$msg_yes" ]; then - err=$( mkdir -p "$pw_home_dir" 2>&1 ) - if [ $? -ne $SUCCESS ]; then - f_dialog_msgbox "$msg_warning $err\n" - elif [ -e "$pw_home_dir" ]; then - err=$( chown -R "$pw_uid:$pw_gid" \ - "$pw_home_dir" 2>&1 ) - [ $? -eq $SUCCESS ] || - f_dialog_msgbox "$msg_warning $err\n" + if f_eval_catch $funcname mkdir \ + 'mkdir -p "%s"' "$pw_home_dir" + then + f_eval_catch $funcname chown \ + 'chown -R "%s" "%s"' \ + "$pw_uid:$pw_gid" "$pw_home_dir" fi fi - if [ "$pw_dotfiles_create" = "$msg_yes" ]; then - err=$( copy_dotfiles 2>&1 ) || - f_dialog_msgbox "$msg_warning $err\n" - fi + [ "$pw_dotfiles_create" = "$msg_yes" ] && + f_eval_catch $funcname copy_dotfiles copy_dotfiles user="$pw_name" f_quietly pw usershow -n "$pw_name" && @@ -157,35 +144,27 @@ save_changes() [ "$pw_shell" ] && cmd="$cmd -s '$pw_shell'" [ "$pw_uid" ] && cmd="$cmd -u '$pw_uid'" if [ "$pw_password_disable" ]; then - cmd="$cmd -h -" + f_eval_catch $funcname pw '%s -h -' "$cmd" elif [ "$pw_password" ]; then - cmd="echo \"\$pw_password\" | $cmd -h 0" - fi - f_dprintf "cmd=%s" "$cmd" - err=$( eval $cmd 2>&1 ) - retval=$? - if [ $retval -ne $SUCCESS ]; then - f_dialog_msgbox "$msg_error $err\n" - return $retval - fi + echo "$pw_password" | + f_eval_catch $funcname pw '%s -h 0' "$cmd" + else + f_eval_catch $funcname pw '%s' "$cmd" + fi || return $? f_show_msg "$msg_login_updated" if [ "$pw_home_create" = "$msg_yes" ]; then - err=$( mkdir -p "$pw_home_dir" ) - if [ $? -ne $SUCCESS ]; then - f_dialog_msgbox "$msg_warning $err\n" - elif [ -e "$pw_home_dir" ]; then - err=$( chown -R "$pw_uid:$pw_gid" \ - "$pw_home_dir" 2>&1 ) - [ $? -eq $SUCCESS ] || - f_dialog_msgbox "$msg_warning $err\n" + if f_eval_catch $funcname mkdir \ + 'mkdir -p "%s"' "$pw_home_dir" + then + f_eval_catch $funcname chown \ + 'chown -R "%i:%i" "%s"' \ + "$pw_uid" "$pw_gid" "$pw_home_dir" fi fi - if [ "$pw_dotfiles_create" = "$msg_yes" ]; then - err=$( copy_dotfiles 2>&1 ) || - f_dialog_msgbox "$msg_warning $err\n" - fi + [ "$pw_dotfiles_create" = "$msg_yes" ] && + f_eval_catch $funcname copy_dotfiles copy_dotfiles ;; esac diff --git a/usr.sbin/bsdconfig/usermgmt/usermgmt b/usr.sbin/bsdconfig/usermgmt/usermgmt index 5335bd6..79fbc95 100755 --- a/usr.sbin/bsdconfig/usermgmt/usermgmt +++ b/usr.sbin/bsdconfig/usermgmt/usermgmt @@ -40,8 +40,8 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr USERMGMT_HELPFILE=$BSDCFG_LIBE/$APP_DIR/include/usermgmt.hlp -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}" ############################################################ FUNCTIONS |