diff options
author | dteske <dteske@FreeBSD.org> | 2012-12-28 23:49:17 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2012-12-28 23:49:17 +0000 |
commit | 34882b31ed4d9c4888e719983cf5ed72416f9fc6 (patch) | |
tree | f0fbb2f6eee49f30f2a89cd419a44197517561ee /usr.sbin/bsdconfig/share | |
parent | b91b6fc81be438c7e519ccdcf3f3159d27fed2d5 (diff) | |
download | FreeBSD-src-34882b31ed4d9c4888e719983cf5ed72416f9fc6.zip FreeBSD-src-34882b31ed4d9c4888e719983cf5ed72416f9fc6.tar.gz |
Allow debug output to be logged to a file (set $debugFile to target pathname)
or both stdout and a file (precede $debugFile pathname with a plus-sign, `+').
Diffstat (limited to 'usr.sbin/bsdconfig/share')
-rw-r--r-- | usr.sbin/bsdconfig/share/common.subr | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/usr.sbin/bsdconfig/share/common.subr b/usr.sbin/bsdconfig/share/common.subr index 6d56ecf..071325c 100644 --- a/usr.sbin/bsdconfig/share/common.subr +++ b/usr.sbin/bsdconfig/share/common.subr @@ -72,7 +72,12 @@ f_dprintf() { [ "$debug" ] || return $SUCCESS local fmt="$1"; shift + case "$debugFile" in ""|+*) printf "DEBUG: $fmt${fmt:+\n}" "$@" >&${TERMINAL_STDOUT_PASSTHRU:-1} + esac + [ "${debugFile#+}" ] && + printf "DEBUG: $fmt${fmt:+\n}" "$@" >> "${debugFile#+}" + return $SUCCESS } # f_err $fmt [ $opts ... ] @@ -517,6 +522,25 @@ eval exec $TERMINAL_STDERR_PASSTHRU\>\&2 [ "$debug" ] && export debug # +# Truncate the debug file upon initialization (now). Note that we will trim a +# leading plus (`+') from the value of debugFile to support persistant meaning +# that f_dprintf() should print both to standard output and $debugFile (minus +# the leading plus, of course). +# +_debug_file="${debugFile#+}" +if [ "$_debug_file" ]; then + if ( umask 022 && :> "$_debug_file" ); then + f_dprintf "Successfully initialized debugFile \`%s'" \ + "$_debug_file" + else + unset debugFile + f_dprintf "Unable to initialize debugFile \`%s'" \ + "$_debug_file" + fi +fi +unset _debug_file + +# # Log our operating environment for debugging purposes # f_dprintf "UNAME_S=[%s] UNAME_P=[%s] UNAME_R=[%s]" \ |