From owner-svn-soc-all@FreeBSD.ORG Sat Jun 30 14:08:47 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 24C101065696 for ; Sat, 30 Jun 2012 14:08:45 +0000 (UTC) (envelope-from tzabal@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sat, 30 Jun 2012 14:08:45 +0000 Date: Sat, 30 Jun 2012 14:08:45 +0000 From: tzabal@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120630140845.24C101065696@hub.freebsd.org> Cc: Subject: socsvn commit: r238632 - soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Jun 2012 14:08:47 -0000 Author: tzabal Date: Sat Jun 30 14:08:44 2012 New Revision: 238632 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238632 Log: Add the function clear_xml() that replaces the characters of the report that have special meaning in XML with the predefined entity references. 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 Sat Jun 30 14:05:20 2012 (r238631) +++ soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh Sat Jun 30 14:08:44 2012 (r238632) @@ -1,9 +1,9 @@ #!/bin/sh # -# Crashreport is a program that is responsible to locate, collect and send -# the debugging information of a FreeBSD kernel crash to a central machine -# that collects these reports for analysis from the FreeBSD community and -# the FreeBSD developers. +# Crashreport is a program that is responsible to locate, collect, form and +# transfer the debugging information of a FreeBSD kernel crash to a central +# machine that collects these reports for analysis from the FreeBSD community +# and the FreeBSD developers. # [ -f /etc/rc.conf ] && . /etc/rc.conf @@ -21,6 +21,28 @@ echo "${PROG}: Error: $*" 1>&2 } +# Replace the characters of the report that have special +# meaning in XML with the predefined entity references +clear_xml() +{ + local istag= + local linenumber=0 + while read line; do + istag='false' + linenumber=$((linenumber+1)) + echo "${line}" | egrep "${tags}" > /dev/null + if [ $? -eq 0 ]; then + istag='true' + fi + if [ "${istag}" == 'false' ]; then + echo "${line}" | grep '[&<>]' > /dev/null + if [ $? -eq 0 ]; then + sed -i '' "${linenumber}s/ /dev/null 2>&1 @@ -138,14 +160,16 @@ ## Form the report data=`mktemp /tmp/crashreport.XXXXXX` -tmp_file=`mktemp /tmp/crashreport.XXXXXX` -orig_IFS="${IFS}" -IFS=";" commands1="date/3;hostname/5;ostype/6;osrelease/7;version/8;machine/9" commands2="ps -axl;vmstat -s;vmstat -m;vmstat -z;vmstat -i;pstat -T;pstat -s;\ iostat;ipcs -a;ipcs -T;nfsstat;netstat -s;netstat -m;netstat -id;netstat -anr;\ netstat -anA;netstat -aL;fstat;dmesg;kernel config;ddb capture buffer" +tags="()|(
)|()|()|()\ +|()|(
)|()|()|()|()|()\ +|()|()|()|()" start=3 +orig_IFS="${IFS}" +IFS=";" echo "" > ${data} echo "" >> ${data} @@ -172,7 +196,10 @@ echo "" >> ${data} if [ "${type}" == 'vmcore' ]; then - # For: date, hostname, ostype, osrelease, version, machine + # A temporary-auxiliary file for the extraction + tmp_file=`mktemp /tmp/crashreport.XXXXXX` + + # For date, hostname, ostype, osrelease, version, machine for cmd in $commands1; do echo "" >> ${data} echo "" >> ${data} @@ -185,7 +212,7 @@ echo "" >> ${data} done - # Panic Message (panic) + # Panic Message echo "" >> ${data} echo "" >> ${data} echo "panic" >> ${data} @@ -197,7 +224,7 @@ echo "" >> ${data} echo "" >> ${data} - # Backtrace (bt from kgdb) + # Backtrace echo "" >> ${data} echo "" >> ${data} echo "backtrace" >> ${data} @@ -227,7 +254,7 @@ echo "" >> ${data} echo "" >> ${data} - # From ps -axl until end + # For ps -axl until end for cmd in $commands2; do echo "" >> ${data} echo "" >> ${data} @@ -242,10 +269,13 @@ echo "" >> ${data} echo "" >> ${data} done + + clear_xml + rm "${tmp_file}" else # A temporary directory for the contents of the textdump tmp_dir=`mktemp -d /tmp/crashreport.XXXXXX` - tar -xvf "${_dumpdir}/${_file}" -C "${tmp_dir}" + tar -xf "${_dumpdir}/${_file}" -C "${tmp_dir}" # A valid textdump can contain up to 5 files with the following names: # ddb.txt, config.txt, msgbuf.txt, panic.txt and version.txt @@ -255,7 +285,7 @@ while read line; do echo "${line}" | egrep '^.+> [a-z ]+$' > /dev/null if [ $? -eq 0 ]; then - if [ ${flag} == false ]; then + if [ "${flag}" == false ]; then flag='true' echo "" >> ${data} echo "" >> ${data} @@ -276,7 +306,7 @@ else echo "${line}" >> ${data} fi - done < ${orig_file} + done < "${tmp_dir}/ddb.txt" echo "" >> ${data} echo "" >> ${data} fi @@ -324,7 +354,8 @@ echo "" >> ${data} echo "" >> ${data} fi - + + clear_xml rm -r "${tmp_dir}" fi @@ -346,7 +377,7 @@ exit 1 fi -rm -f "${data}" "${tmp_file}" +rm -f "${data}" ## Send the report to the Central Collector machine