From owner-svn-src-all@FreeBSD.ORG Fri Dec 28 23:49:18 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8DAA89F9; Fri, 28 Dec 2012 23:49:18 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 59ED88FC0C; Fri, 28 Dec 2012 23:49:18 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBSNnIQI029048; Fri, 28 Dec 2012 23:49:18 GMT (envelope-from dteske@svn.freebsd.org) Received: (from dteske@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBSNnILu029047; Fri, 28 Dec 2012 23:49:18 GMT (envelope-from dteske@svn.freebsd.org) Message-Id: <201212282349.qBSNnILu029047@svn.freebsd.org> From: Devin Teske Date: Fri, 28 Dec 2012 23:49:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244799 - head/usr.sbin/bsdconfig/share X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Dec 2012 23:49:18 -0000 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]" \