Index: etc/rc.d/savecore =================================================================== --- etc/rc.d/savecore +++ etc/rc.d/savecore @@ -70,7 +70,7 @@ if savecore -C "${dev}" >/dev/null; then savecore ${savecore_flags} ${dumpdir} ${dumpdev} if checkyesno crashinfo_enable; then - ${crashinfo_program} -d ${dumpdir} + ${crashinfo_program} -b -d ${dumpdir} fi sync else Index: usr.sbin/crashinfo/crashinfo.8 =================================================================== --- usr.sbin/crashinfo/crashinfo.8 +++ usr.sbin/crashinfo/crashinfo.8 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 28, 2008 +.Dd April 19, 2017 .Dt CRASHINFO 8 .Os .Sh NAME @@ -88,6 +88,12 @@ .Pp The options are as follows: .Bl -tag -width indent +.It Fl b +Run in batch mode. Write most messages to the +.Pa core.txt.XX +file instead of the terminal. This flag is used when +.Nm +is run during boot. .It Fl d Ar crashdir Specify an alternate core dump directory. The default crash dump directory is Index: usr.sbin/crashinfo/crashinfo.sh =================================================================== --- usr.sbin/crashinfo/crashinfo.sh +++ usr.sbin/crashinfo/crashinfo.sh @@ -31,10 +31,16 @@ usage() { - echo "usage: crashinfo [-d crashdir] [-n dumpnr] [-k kernel] [core]" + echo "usage: crashinfo [-b] [-d crashdir] [-n dumpnr]" \ + "[-k kernel] [core]" exit 1 } +gdb_six() +{ + $GDB --version | grep -q '^GNU gdb 6\.' +} + # Run a single gdb command against a kernel file in batch mode. # The kernel file is specified as the first argument and the command # is given in the remaining arguments. @@ -44,10 +50,10 @@ k=$1 ; shift - if [ -x /usr/local/bin/gdb ]; then - /usr/local/bin/gdb -batch -ex "$@" $k + if gdb_six; then + echo -e "$@" | $GDB -x /dev/stdin -batch $k else - echo -e "$@" | /usr/bin/gdb -x /dev/stdin -batch $k + $GDB -batch -ex "$@" $k fi } @@ -80,12 +86,17 @@ done } +BATCH=false CRASHDIR=/var/crash DUMPNR= +GDB= KERNEL= -while getopts "d:n:k:" opt; do +while getopts "bd:n:k:" opt; do case "$opt" in + b) + BATCH=true + ;; d) CRASHDIR=$OPTARG ;; @@ -140,6 +151,28 @@ FILE=$CRASHDIR/core.txt.$DUMPNR HOSTNAME=`hostname` +if $BATCH; then + echo "Writing crash summary to $FILE." + exec > $FILE 2>&1 +fi + +# Try to find gdb in the user's PATH. +if ! GDB=`which gdb`; then + # /usr/local/bin is not in the PATH during boot. + if [ -x /usr/local/bin/gdb ]; then + GDB=/usr/local/bin/gdb + else + echo "Please install GDB and run 'crashinfo' again." >&2 + echo "The easiest way to install GDB is: pkg install gdb" >&2 + exit 1 + fi +fi + +# Try to avoid ancient versions of gdb, such as 6.1.1 in the base system. +if gdb_six && test -x /usr/local/bin/gdb; then + GDB=/usr/local/bin/gdb +fi + if [ ! -e $VMCORE ]; then echo "$VMCORE not found" exit 1 @@ -162,8 +195,6 @@ exit 1 fi -echo "Writing crash summary to $FILE." - umask 077 # Simulate uname @@ -172,7 +203,10 @@ version=$(gdb_command $KERNEL 'printf "%s", version' | tr '\t\n' ' ') machine=$(gdb_command $KERNEL 'printf "%s", machine') -exec > $FILE 2>&1 +if ! $BATCH; then + echo "Writing crash summary to $FILE." + exec > $FILE 2>&1 +fi echo "$HOSTNAME dumped core - see $VMCORE" echo