Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 05 Jun 2012 10:38:39 +0000
From:      tzabal@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r237121 - soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport
Message-ID:  <20120605103839.AFAA6106566B@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tzabal
Date: Tue Jun  5 10:38:39 2012
New Revision: 237121
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=237121

Log:
  Updated version of crashreport. Patch from Lars Engels is included.

Modified:
  soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh

Modified: soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh
==============================================================================
--- soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh	Tue Jun  5 09:49:31 2012	(r237120)
+++ soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh	Tue Jun  5 10:38:39 2012	(r237121)
@@ -6,9 +6,10 @@
 # the FreeBSD developers.
 #
 
-. /etc/rc.conf
+[ -f /etc/rc.conf ] && . /etc/rc.conf
 
-PROG=`/usr/bin/basename $0`
+# Basename
+PROG=${0##*/}
 
 print_usage()
 {
@@ -31,7 +32,7 @@
 
 ## Check if the user that executes the script is root
 user=`/usr/bin/id -u`
-if [ "${user}" != "0" ]; then
+if [ ${user} -ne 0 ]; then
 	error 'Only the superuser (uid 0) can use this program.'
 	exit 1
 fi
@@ -39,15 +40,15 @@
 
 ## Get positional parameters
 while getopts "d:f:e:" opt; do
-	case "$opt" in
+	case "${opt}" in
 	d)
-		_dumpdir=$OPTARG
+		_dumpdir="${OPTARG}"
 		;;
 	f)
-		_file=$OPTARG
+		_file="${OPTARG}"
 		;;
 	e)
-		_email=$OPTARG
+		_email="${OPTARG}"
 		;;
 	*)
 		print_usage
@@ -61,9 +62,9 @@
 if [ -z "${_dumpdir}" ]; then
 	# dumpdir of /etc/rc.conf
 	if [ -z "${dumpdir}" ]; then
-		_dumpdir=${DUMPDIR}
+		_dumpdir="${DUMPDIR}"
 	else
-		_dumpdir=${dumpdir}
+		_dumpdir="${dumpdir}"
 	fi
 fi
 
@@ -85,20 +86,26 @@
 CORE="${_dumpdir}/core.txt"
 TEXTDUMP="${_dumpdir}/textdump.tar"
 
+flag=1
 if [ -z "${_file}" ]; then
 	# Find it using the file bounds
 	if [ -r "${BOUNDS}" ]; then
 		value=`head -n 1 ${BOUNDS}`
-		X=$((value - 1))
-		if [ -f "${CORE}.${X}" ]; then
-			_file=`basename "${CORE}.${X}"`
-		else
-			_file=`basename "${TEXTDUMP}.${X}"`
+		if [ ${value} -ge 1 ]; then
+			flag=0
+			X=$((value - 1))
+			if [ -f "${CORE}.${X}" ]; then
+				_file="${CORE##*/}.${X}"
+			else
+				_file="${TEXTDUMP##*/}.${X}"
+			fi
 		fi
+	fi
+
 	# Otherwise, use this (heavier) way
-	else
-		_file=`ls ${_dumpdir} | egrep '[a-z]+\.[a-z]+\.[0-9]+' | \
-		       sort -n -t . -k 3 | tail -1`
+	if [ ${flag} -eq 1 ]; then
+		_file="`ls ${_dumpdir} | egrep '[a-z]+\.[a-z]+\.[0-9]+' | \
+		       sort -n -t . -k 3 | tail -1`"
 	fi
 fi
 
@@ -114,16 +121,16 @@
 	_email="${email}"
 fi
 
-if [ -z "$_email" ]; then
+if [ -z "${_email}" ]; then
 	error 'No email address for contact is specified.'
 	exit 6
 fi
 
 # Check if the given email address is valid based on its format.
-echo ${_email} | egrep '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$' \
- > /dev/null
+echo "${_email}" | egrep '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$' \
+ > /dev/null 2>&1
 
-if [ "$?" != "0" ]; then
+if [ $? -ne 0 ]; then
 	error "Email address ${_email} is invalid."
 	exit 7
 fi
@@ -134,14 +141,16 @@
 email_file=`mktemp /tmp/crashreport.XXXXXX`
 echo "${_email}" > ${email_file}
 
-tar -czf ${report} -C ${_dumpdir} ${_file} -C `dirname ${email_file}` \
- `basename ${email_file}`
+tar -czf ${report} -C "${_dumpdir}" "${_file}" -C ${email_file%/*} \
+ ${email_file##*/}
 
-if [ "$?" != "0" ]; then
-	error 'An error occurred when bundling the report.'
+if [ $? -ne 0 ]; then
+	error 'An error occurred while bundling the report.'
 	exit 8
 fi
 
+rm -f "${email_file}"
+
 
 ## Send the report to the Central Collector machine
 user="reporter"
@@ -183,11 +192,18 @@
 4A2OywvWcs45QnlxYmKUIL6x8stKQAbtuHkbda3v/4ts/+6Y0jss
 -----END RSA PRIVATE KEY-----" > ${user_private_key_file}
 
-scp -o GlobalKnownHostsFile=${host_public_key_file} -o BatchMode=yes \
- -i ${user_private_key_file} -q ${report} ${user}@${hostname}:
+scp -o GlobalKnownHostsFile="${host_public_key_file}" -o BatchMode=yes \
+ -i "${user_private_key_file}" -q "${report}" "${user}@${hostname}:"
+
+if [ $? -ne 0 ]; then
+	error 'An error occurred while sending the report.'
+	exit 9
+fi
+
+rm -f ${host_public_key_file} ${user_private_key_file}
 
 
 ## Everything went smoothly
-echo "Crash report has been sent successfully.\
-Check your email for confirmation."
-exit 0
\ No newline at end of file
+echo "Kernel crash report has been sent successfully. \
+Check your email for confirmation of the report."
+exit 0



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120605103839.AFAA6106566B>