diff options
author | dteske <dteske@FreeBSD.org> | 2012-12-21 19:26:17 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2012-12-21 19:26:17 +0000 |
commit | 10fd5103d05e0e84415fd9b26eebe9c98c8880fc (patch) | |
tree | d18d863cf5690553d6d8e68efe62f69a60817d61 /usr.sbin/bsdconfig/share | |
parent | 1906ac57cd7e750371015d64e4b50a2807c3ec75 (diff) | |
download | FreeBSD-src-10fd5103d05e0e84415fd9b26eebe9c98c8880fc.zip FreeBSD-src-10fd5103d05e0e84415fd9b26eebe9c98c8880fc.tar.gz |
Improve the debugging abilities and clean up debug messages. In most cases,
all one has to do is set the environment variable DEBUGGING to get the debug
messages to appear on the console.
Diffstat (limited to 'usr.sbin/bsdconfig/share')
-rw-r--r-- | usr.sbin/bsdconfig/share/common.subr | 38 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/dialog.subr | 2 |
2 files changed, 33 insertions, 7 deletions
diff --git a/usr.sbin/bsdconfig/share/common.subr b/usr.sbin/bsdconfig/share/common.subr index 8050939..8bf552a 100644 --- a/usr.sbin/bsdconfig/share/common.subr +++ b/usr.sbin/bsdconfig/share/common.subr @@ -27,6 +27,15 @@ if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1 # # $FreeBSD$ # +############################################################ CONFIGURATION + +# +# Default file descriptors to link to stdout/stderr for passthru allowing +# redirection within a sub-shell to bypass directly to the terminal. +# +: ${TERMINAL_STDOUT_PASSTHRU:=3}} +: ${TERMINAL_STDERR_PASSTHRU:=4}} + ############################################################ GLOBALS # @@ -56,6 +65,14 @@ f_dprintf() { : this page intentionally left blank } +[ "$DEBUGGING" ] && f_dprintf() +{ + local fmt="$1" + shift + printf "$fmt${fmt:+\n}" "$@" \ + >&${TERMINAL_STDOUT_PASSTHRU:-1} +} && + export DEBUGGING # f_err $fmt [ $opts ... ] # @@ -63,7 +80,7 @@ f_dprintf() # f_err() { - printf "$@" >&2 + printf "$@" >&${TERMINAL_STDERR_PASSTHRU:-2} } # f_quietly $command [ $arguments ... ] @@ -181,6 +198,7 @@ f_show_help() f_include() { local file="$1" + f_dprintf "f_include: file=[%s]" "$file" . "$file" || exit $? } @@ -202,7 +220,7 @@ f_include_lang() local file="$1" local lang="${LANG:-$LC_ALL}" - f_dprintf "lang=[$lang]" + f_dprintf "f_include_lang: file=[%s] lang=[%s]" "$file" "$lang" if [ -f "$file.$lang" ]; then . "$file.$lang" || exit $? else @@ -247,7 +265,7 @@ f_usage() local file="$1" local lang="${LANG:-$LC_ALL}" - f_dprintf "lang=[$lang]" + f_dprintf "f_usage: file=[%s] lang=[%s]" "$file" "$lang" shift 1 # file @@ -300,7 +318,7 @@ f_index_file() local keyword="$1" local lang="${LANG:-$LC_ALL}" - f_dprintf "lang=[$lang]" + f_dprintf "f_index_file: keyword=[%s] lang=[%s]" "$keyword" "$lang" if [ "$lang" ]; then awk -v keyword="$keyword" "$f_index_file_awk" \ @@ -362,7 +380,8 @@ f_index_menusel_keyword() local indexfile="$1" pgm="$2" local lang="${LANG:-$LC_ALL}" - f_dprintf "lang=[$lang]" + f_dprintf "f_index_menusel_keyword: index=[%s] pgm=[%s] lang=[%s]" \ + "$indexfile" "$pgm" "$lang" if [ -f "$indexfile.$lang" ]; then awk -v pgm="$pgm" \ @@ -424,7 +443,8 @@ f_index_menusel_command() local indexfile="$1" keyword="$2" command local lang="${LANG:-$LC_ALL}" - f_dprintf "lang=[$lang]" + f_dprintf "f_index_menusel_command: index=[%s] key=[%s] lang=[%s]" \ + "$indexfile" "$keyword" "$lang" if [ -f "$indexfile.$lang" ]; then command=$( awk -v key="$keyword" \ @@ -463,4 +483,10 @@ trap 'f_die' SIGTERM SIGPIPE SIGXCPU SIGXFSZ \ SIGFPE SIGTRAP SIGABRT SIGSEGV trap '' SIGALRM SIGPROF SIGUSR1 SIGUSR2 SIGHUP SIGVTALRM +# +# Clone terminal stdout/stderr so we can redirect to it from within sub-shells +# +eval exec $TERMINAL_STDOUT_PASSTHRU\>\&1 +eval exec $TERMINAL_STDERR_PASSTHRU\>\&2 + fi # ! $_COMMON_SUBR diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr index 4f45817..6a6bd45 100644 --- a/usr.sbin/bsdconfig/share/dialog.subr +++ b/usr.sbin/bsdconfig/share/dialog.subr @@ -42,7 +42,7 @@ f_include_lang $BSDCFG_LIBE/include/messages.subr # execution of dialog from within a sub-shell (so-long as its standard output # is explicitly redirected to this file descriptor). # -: ${DIALOG_TERMINAL_PASSTHRU_FD:=3} +: ${DIALOG_TERMINAL_PASSTHRU_FD:=${TERMINAL_STDOUT_PASSTHRU:-3}} ############################################################ GLOBALS |