From 1f1ed24cc5252c0d33d775bb00052462b462f77c Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Thu, 1 Jun 2017 21:23:04 +0000 Subject: [PATCH] crashinfo: add "batch" mode and use it during boot In batch mode, most messages go into the core.txt.N file instead of stdout. Reviewed by: jhb MFC after: 3 days Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D10429 --- etc/rc.d/savecore | 2 +- usr.sbin/crashinfo/crashinfo.8 | 8 +++++++- usr.sbin/crashinfo/crashinfo.sh | 21 ++++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/etc/rc.d/savecore b/etc/rc.d/savecore index bfc61bce3c7e..c39872cf1729 100755 --- a/etc/rc.d/savecore +++ b/etc/rc.d/savecore @@ -70,7 +70,7 @@ savecore_start() 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 diff --git a/usr.sbin/crashinfo/crashinfo.8 b/usr.sbin/crashinfo/crashinfo.8 index 897fc59906d4..653c7cfe3d57 100644 --- a/usr.sbin/crashinfo/crashinfo.8 +++ b/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 @@ and .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 diff --git a/usr.sbin/crashinfo/crashinfo.sh b/usr.sbin/crashinfo/crashinfo.sh index 2326630cdef2..e52c01419b0d 100755 --- a/usr.sbin/crashinfo/crashinfo.sh +++ b/usr.sbin/crashinfo/crashinfo.sh @@ -31,7 +31,8 @@ usage() { - echo "usage: crashinfo [-d crashdir] [-n dumpnr] [-k kernel] [core]" + echo "usage: crashinfo [-b] [-d crashdir] [-n dumpnr]" \ + "[-k kernel] [core]" exit 1 } @@ -93,12 +94,16 @@ find_kernel() done } +BATCH=false CRASHDIR=/var/crash DUMPNR= KERNEL= -while getopts "d:n:k:" opt; do +while getopts "bd:n:k:" opt; do case "$opt" in + b) + BATCH=true + ;; d) CRASHDIR=$OPTARG ;; @@ -153,6 +158,11 @@ INFO=$CRASHDIR/info.$DUMPNR FILE=$CRASHDIR/core.txt.$DUMPNR HOSTNAME=`hostname` +if $BATCH; then + echo "Writing crash summary to $FILE." + exec > $FILE 2>&1 +fi + find_gdb if [ -z "$GDB" ]; then echo "Unable to find a kernel debugger." @@ -181,8 +191,6 @@ elif [ ! -e $KERNEL ]; then exit 1 fi -echo "Writing crash summary to $FILE." - umask 077 # Simulate uname @@ -191,7 +199,10 @@ osrelease=$(gdb_command $KERNEL 'printf "%s", osrelease') 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