Author: dteske
Date: Fri Dec 28 23:49:17 2012
New Revision: 244799
URL: http://svnweb.freebsd.org/changeset/base/244799

Log:
  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, `+').

Modified:
  head/usr.sbin/bsdconfig/share/common.subr

Modified: head/usr.sbin/bsdconfig/share/common.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/common.subr   Fri Dec 28 23:40:13 2012        
(r244798)
+++ head/usr.sbin/bsdconfig/share/common.subr   Fri Dec 28 23:49:17 2012        
(r244799)
@@ -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]" \
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to