summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/share
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2013-04-22 05:02:34 +0000
committerdteske <dteske@FreeBSD.org>2013-04-22 05:02:34 +0000
commit6089bf07c71a6fd15cb36b50f7801a4b09037460 (patch)
tree30a8b20faa65aa281c83e178629b4b01903d9fef /usr.sbin/bsdconfig/share
parent78339bf7f3a0cd62b1bcf122e6ca71e724ee1df9 (diff)
downloadFreeBSD-src-6089bf07c71a6fd15cb36b50f7801a4b09037460.zip
FreeBSD-src-6089bf07c71a6fd15cb36b50f7801a4b09037460.tar.gz
Add new flags `-d' (sets debug=1) and `-D file' (sets debugFile) and
improve debugging initialization. Also fixup USAGE statements while we're here. Also, change initialization of main program to _not_ change working directory, allowing the debugFile to be relative without confusion.
Diffstat (limited to 'usr.sbin/bsdconfig/share')
-rw-r--r--usr.sbin/bsdconfig/share/common.subr86
-rw-r--r--usr.sbin/bsdconfig/share/mustberoot.subr3
2 files changed, 67 insertions, 22 deletions
diff --git a/usr.sbin/bsdconfig/share/common.subr b/usr.sbin/bsdconfig/share/common.subr
index cb9096f..d1a3c00 100644
--- a/usr.sbin/bsdconfig/share/common.subr
+++ b/usr.sbin/bsdconfig/share/common.subr
@@ -62,6 +62,11 @@ export UNAME_S="$(uname -s)" # Operating System (i.e. FreeBSD)
export UNAME_P="$(uname -p)" # Processor Architecture (i.e. i386)
export UNAME_R="$(uname -r)" # Release Level (i.e. X.Y-RELEASE)
+#
+# Default behavior is to call f_debug_init() automatically when loaded.
+#
+: ${DEBUG_SELF_INITIALIZE=1}
+
############################################################ FUNCTIONS
# f_dprintf $fmt [ $opts ... ]
@@ -86,6 +91,59 @@ f_dprintf()
return $SUCCESS
}
+# f_debug_init
+#
+# Initialize debugging. Truncates $debugFile to zero bytes if set.
+#
+f_debug_init()
+{
+ #
+ # Process stored command-line arguments
+ #
+ ( set -- "$ARGV"
+ while getopts d flag > /dev/null; do
+ case "$flag" in
+ d) true; exit;;
+ \?) continue;;
+ esac
+ done
+ false
+ ) && debug=1
+ debugFile=$( set -- "$ARGV"
+ while getopts D flag > /dev/null; do
+ case "$flag" in
+ D) echo "$OPTARG";;
+ \?) continue;;
+ esac
+ done
+ )
+
+ #
+ # Make debugging persistant if set
+ #
+ [ "$debug" ] && export debug
+
+ #
+ # Truncate the debug file upon. 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).
+ #
+ local _debug_file="${debugFile#+}"
+ if [ "$_debug_file" ]; then
+ if ( umask 022 && :> "$_debug_file" ); then
+ f_dprintf "Successfully initialized debugFile \`%s'" \
+ "$_debug_file"
+ [ "${debug+set}" ] ||
+ debug=1 # turn debugging on if not set
+ else
+ unset debugFile
+ f_dprintf "Unable to initialize debugFile \`%s'" \
+ "$_debug_file"
+ fi
+ fi
+}
+
# f_err $fmt [ $opts ... ]
#
# Print a message to stderr (fd=2).
@@ -615,28 +673,14 @@ eval exec $TERMINAL_STDOUT_PASSTHRU\>\&1
eval exec $TERMINAL_STDERR_PASSTHRU\>\&2
#
-# Make debugging persistant if set
+# Self-initialize unless requested otherwise
#
-[ "$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
+f_dprintf "%s: DEBUG_SELF_INITIALIZE=[%s]" \
+ dialog.subr "$DEBUG_SELF_INITIALIZE"
+case "$DEBUG_SELF_INITIALIZE" in
+""|0|[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]) : do nothing ;;
+*) f_debug_init
+esac
#
# Log our operating environment for debugging purposes
diff --git a/usr.sbin/bsdconfig/share/mustberoot.subr b/usr.sbin/bsdconfig/share/mustberoot.subr
index 2ead592..ebfe812 100644
--- a/usr.sbin/bsdconfig/share/mustberoot.subr
+++ b/usr.sbin/bsdconfig/share/mustberoot.subr
@@ -1,6 +1,6 @@
if [ ! "$_MUSTBEROOT_SUBR" ]; then _MUSTBEROOT_SUBR=1
#
-# Copyright (c) 2006-2012 Devin Teske
+# Copyright (c) 2006-2013 Devin Teske
# All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -250,6 +250,7 @@ f_become_root_via_sudo()
fi
# Re-execute ourselves with sudo(8)
+ f_dprintf "%s: Becoming root via sudo(8)..." mustberoot.subr
if [ $ARGC -gt 0 ]; then
exec sudo "$0" $ARGV
else
OpenPOWER on IntegriCloud